Under construction

Still being built. Things may change

Lexicographic Comparison

Time limit2sMemory limit1024 MB

Summary
Given permutations a and p under position swaps, compare A_x and A_y lexicographically, where A_k is a with p applied k-1 times.
Level

Hard8 of 10

Topics
Array, String matching, Binary search, Segment tree
Solved
No attempts yet

Problem

Consider aa and pp, two permutations of length nn. Initially, a_i=p_i=ia\_i=p\_i=i for all 1≤i≤n1\le i\le n. Let AA be a sequence of permutations such that A_1=aA\_1=a and A_i,j=A_i−1,p_jA\_{i,j}=A\_{i-1,p\_j} for all i≥1i\ge 1 and 1≤j≤n1\le j\le n.

There are three types of operations, where xx and yy are positive integers:

  1. swap_a xx yy: swap a_xa\_x and a_ya\_y, where 1≤x,y≤n1\le x, y\le n.
  2. swap_p xx yy: swap p_xp\_x and p_yp\_y, where 1≤x,y≤n1\le x, y\le n.
  3. cmp xx yy: compare A_xA\_x with A_yA\_y lexicographically.

For each operation of type 3, output the relationship between A_xA\_x and A_yA\_y. A permutation ss is lexicographically smaller than a permutation tt if and only if there exists an index ii such that s_i<t_is\_i<t\_i and s_j=t_js\_j=t\_j for all 1≤j<i1\le j<i.

Input

The first line contains an integer TT (1≤T≤1051\le T\le 10^5), the number of test cases. For each test case:

The first line contains integers nn and qq (1≤n,q≤1051\le n, q\le 10^5), the length of the permutations and the number of operations.

Each of the following qq lines contains a string ff and two integers xx and yy representing an operation. The string ff is one of swap_a, swap_p, and cmp. If ff is swap_a or swap_p, then 1≤x,y≤n1 \le x, y \le n. If ff is cmp, then 1≤x,y≤10181 \le x, y \le 10^{18}.

The sum of nn and the sum of qq over all tests do not exceed 10510^5.

Output

For each test case, output one line per cmp query. Output < if A_xA\_x is lexicographically smaller than A_yA\_y, > if A_xA\_x is lexicographically greater than A_yA\_y (that is, A_yA\_y is lexicographically smaller than A_xA\_x), and = if A_x=A_yA\_x = A\_y.

Examples1

  1. Example 1

    Input
    2
    5 5
    cmp 1 2
    swap_p 1 2
    cmp 1 2
    swap_a 1 2
    cmp 1 2
    1 1
    swap_a 1 1
    
    Expected output
    =
    <
    >