You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.

You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such query. Then the queries are the following:

  * 1~x~y (1 ≤ x, y ≤ n, x ≠ y) — add an undirected edge between the vertices (x + last - 1)~mod~n + 1 and (y + last - 1)~mod~n + 1 if it doesn't exist yet, otherwise remove it; 
  * 2~x~y (1 ≤ x, y ≤ n, x ≠ y) — check if there exists a path between the vertices (x + last - 1)~mod~n + 1 and (y + last - 1)~mod~n + 1, which goes only through currently existing edges, and set last to 1 if so and 0 otherwise. 



Good luck!

Input

The first line contains two integer numbers n and m (2 ≤ n, m ≤ 2 ⋅ 10^5) — the number of vertices and the number of queries, respectively.

Each of the following m lines contains a query of one of two aforementioned types. It is guaranteed that there is at least one query of the second type.

Output

Print a string, consisting of characters '0' and '1'. The i-th character should be the answer to the i-th query of the second type. Therefore the length of the string should be equal to the number of queries of the second type.

Examples

Input


5 9
1 1 2
1 1 3
2 3 2
1 2 4
2 3 4
1 2 4
2 3 4
1 1 3
2 4 3


Output


1010


Input


3 9
1 1 2
1 2 3
1 3 1
2 1 3
1 3 2
2 2 3
1 1 2
2 1 2
2 1 2


Output


1101

Note

The converted queries in the first example are:

  * 1 1 2 
  * 1 1 3 
  * 2 3 2 
  * 1 3 5 
  * 2 4 5 
  * 1 2 4 
  * 2 3 4 
  * 1 2 4 
  * 2 5 4 



The converted queries in the second example are:

  * 1 1 2 
  * 1 2 3 
  * 1 3 1 
  * 2 1 3 
  * 1 1 3 
  * 2 3 1 
  * 1 2 3 
  * 2 2 3 
  * 2 1 2 
#include <bits/stdc++.h>
const int MN = 200005, MQ = 200005, MS = 524288;
int N, Q;
int op[MQ], qu[MQ], qv[MQ], nxp0[MQ], nxp1[MQ];
inline void Prework() {
  std::map<std::pair<int, int>, int> Edg;
  for (int i = Q; i >= 1; i--) {
    if (op[i] == 2) continue;
    int u0 = qu[i], v0 = qv[i], u1 = u0 % N + 1, v1 = v0 % N + 1;
    if (u0 > v0) std::swap(u0, v0);
    if (u1 > v1) std::swap(u1, v1);
    std::pair<int, int> e0(u0, v0), e1(u1, v1);
    nxp0[i] = Edg.find(e0) != Edg.end() ? Edg[e0] : 2 * Q + 2;
    nxp1[i] = Edg.find(e1) != Edg.end() ? Edg[e1] : 2 * Q + 2;
    Edg[e0] = i << 1, Edg[e1] = i << 1 | 1;
  }
}
int fa[MN], rnk[MN];
int ff(int x) { return fa[x] ? ff(fa[x]) : x; }
int stk[MQ], top;
inline void merge(int u, int v) {
  u = ff(u), v = ff(v);
  if (u == v) return;
  if (rnk[u] < rnk[v]) std::swap(u, v);
  fa[v] = u, rnk[u] += rnk[v];
  stk[++top] = v;
}
int lastans;
std::vector<std::pair<int, int> > V[MS];
bool lsp0[MQ], lsp1[MQ];
void Insert(int i, int l, int r, int a, int b, std::pair<int, int> x) {
  if (r < a || b < l) return;
  if (a <= l && r <= b) {
    V[i].push_back(x);
    return;
  }
  int mid = (l + r) >> 1;
  Insert(i << 1, l, mid, a, b, x);
  Insert(i << 1 | 1, mid + 1, r, a, b, x);
}
void Solve(int rt, int l, int r) {
  int nowtop = top;
  for (auto e : V[rt]) merge(e.first, e.second);
  if (l == r) {
    int u0 = qu[l], v0 = qv[l];
    int u1 = u0 % N + 1, v1 = v0 % N + 1;
    if (lastans) std::swap(u0, u1), std::swap(v0, v1);
    if (op[l] == 1) {
      bool l0 = lsp0[l], l1 = lsp1[l];
      if (lastans) std::swap(l0, l1);
      if (!l0) {
        int nxt = (lastans ? nxp1 : nxp0)[l], pos = nxt >> 1;
        (nxt & 1 ? lsp1 : lsp0)[pos] = 1;
        if (pos >= l + 2)
          Insert(1, 1, Q, l + 1, pos - 1, std::pair<int, int>(u0, v0));
      }
      if (l1) {
        int nxt = (lastans ? nxp0 : nxp1)[l], pos = nxt >> 1;
        (nxt & 1 ? lsp1 : lsp0)[pos] = 1;
        if (pos >= l + 2)
          Insert(1, 1, Q, l + 1, pos - 1, std::pair<int, int>(u1, v1));
      }
    } else
      putchar('0' + (lastans = ff(u0) == ff(v0)));
  } else {
    int mid = (l + r) >> 1;
    Solve(rt << 1, l, mid);
    Solve(rt << 1 | 1, mid + 1, r);
  }
  for (int v; top > nowtop; --top)
    v = stk[top], rnk[fa[v]] -= rnk[v], fa[v] = 0;
}
int main() {
  scanf("%d%d", &N, &Q);
  for (int i = 1; i <= Q; ++i) scanf("%d%d%d", &op[i], &qu[i], &qv[i]);
  if (N == 2) {
    int a = 0;
    for (int i = 1; i <= Q; ++i)
      if (op[i] == 1)
        a ^= 1;
      else
        putchar(a ? '1' : '0');
    return 0;
  }
  Prework();
  for (int i = 1; i <= N; ++i) rnk[i] = 1;
  Solve(1, 1, Q);
  return 0;
}
