import re


def replace_table_name_with_query(table_name: str, table_query: str, original_query: str):
    """
    Replaces the table_name with the table_query in the original_query.
    """
    regular_expression = r" ?`?rj-smtr.*{}`? ?".format(table_name)
    find_counts = len(re.findall(regular_expression, original_query))
    return re.sub(regular_expression, f"({table_query})", original_query), find_counts