1217_F. Forced Online Queries Problem_33358
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>
using namespace std;
const int N = 200005;
const int SIZE = 500;
set<pair<int, int> > now, pre;
struct Node {
  int u, v, fa, dep;
};
stack<Node> s;
int n, m;
int op[N], x[N], y[N];
struct DSU {
  int fa[N], dep[N];
  void init(int n) {
    for (int i = 1; i <= n; i++) fa[i] = i, dep[i] = 1;
    return;
  }
  int getf(int v) {
    if (v == fa[v])
      return v;
    else
      return getf(fa[v]);
  }
  bool merge(int u, int v, bool flag) {
    int f1 = getf(u), f2 = getf(v);
    if (f1 == f2) return false;
    if (dep[f1] < dep[f2]) swap(f1, f2);
    if (flag) s.push((Node){f1, f2, fa[f2], dep[f1]});
    fa[f2] = f1;
    dep[f1] = max(dep[f2] + 1, dep[f1]);
    return true;
  }
} Dset;
void remove(int u, int v) {
  if (u > v) swap(u, v);
  pair<int, int> e = make_pair(u, v);
  if (pre.count(e)) now.insert(e), pre.erase(e);
  return;
}
void add(int u, int v) {
  if (u > v) swap(u, v);
  pair<int, int> e = make_pair(u, v);
  if (now.count(e))
    now.erase(e);
  else
    now.insert(e);
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &op[i], &x[i], &y[i]);
  int last = 0;
  for (int i = 1; i <= m; i += SIZE) {
    for (int j = i; j <= min(m, i + SIZE - 1); j++)
      if (op[j] == 1) remove(x[j], y[j]), remove(x[j] % n + 1, y[j] % n + 1);
    Dset.init(n);
    for (auto [u, v] : pre) Dset.merge(u, v, false);
    while (!s.empty()) s.pop();
    for (int j = i; j <= min(m, i + SIZE - 1); j++) {
      x[j] = (x[j] + last - 1) % n + 1, y[j] = (y[j] + last - 1) % n + 1;
      if (x[j] > y[j]) swap(x[j], y[j]);
      if (op[j] == 1)
        add(x[j], y[j]);
      else {
        while (!s.empty()) {
          Dset.dep[s.top().u] = s.top().dep;
          Dset.fa[s.top().v] = s.top().fa;
          s.pop();
        }
        for (auto [u, v] : now) Dset.merge(u, v, true);
        last = Dset.getf(x[j]) == Dset.getf(y[j]);
        printf("%d", last);
      }
    }
    for (auto it : now) pre.insert(it);
    now.clear();
  }
  return 0;
}
