def insert_query(connection, query):
    """
    Inserts a query into the corresponding database table
    :param connection: database connection
    :param query: user query
    :return: last row of the table
    """
    cursor = connection.cursor()
    sql = ("INSERT INTO Query(Topic, StartDate, EndDate, MinLikes, MinRetweets)\n"
           "VALUES(?, ?, ?, ?, ?);")
    values = query
    cursor.execute(sql, values)
    return cursor.lastrowid