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>
#pragma GCC optimize(3)
using namespace std;
void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -f;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  x *= f;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (!x) return;
  print(x / 10), putchar(x % 10 + 48);
}
void write(int x) {
  if (!x)
    putchar('0');
  else
    print(x);
  putchar('\n');
}
const int maxn = 1e6 + 10;
const int inf = 1e9;
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int B = 700;
int n, m;
struct Q {
  int op, x, y, lst;
} a[maxn];
int id[maxn], fa[maxn], top, rev[maxn];
set<int> e[maxn];
multiset<int> c[maxn];
pair<int, int> sta[maxn];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int find(set<int> &s, int y) {
  auto i = s.lower_bound(y);
  if (i == s.end() || *i != y) return 0;
  return 1;
}
int find(multiset<int> &s, int y) {
  auto i = s.lower_bound(y);
  if (i == s.end() || *i != y) return 0;
  return 1;
}
void link(int x, int y) {
  x = find(x), y = find(y);
  if (x != y) fa[x] = y;
}
int inc(int x) { return x % n + 1; }
void rebuild(int t) {
  for (int i = 1; i <= n; i++) c[i].clear();
  top = 0;
  auto make = [&](int x, int y) {
    if (find(e[x], y))
      e[x].erase(y), e[y].erase(x), sta[++top] = make_pair(x, y);
  };
  for (int i = t + 1; i <= t + B; i++)
    if (a[i].op == 1) make(inc(a[i].x), inc(a[i].y)), make(a[i].x, a[i].y);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= n; i++)
    for (auto x : e[i]) link(i, x);
  for (int i = 1; i <= top; i++) {
    int x = find(sta[i].first), y = find(sta[i].second);
    if (x != y) c[x].insert(y), c[y].insert(x);
  }
  for (int i = 1; i <= top; i++) {
    int x = sta[i].first, y = sta[i].second;
    e[x].insert(y), e[y].insert(x);
  }
}
int use[maxn], vis[maxn], uu;
void dfs(int x) {
  vis[x] = 1;
  use[++uu] = x;
  for (auto v : c[x])
    if (!vis[v]) dfs(v);
}
int main() {
  read(n), read(m);
  for (int i = 1; i <= m; i++) read(a[i].op), read(a[i].x), read(a[i].y);
  int lst = 0;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    a[i].lst = lst;
    int u = (a[i].x + lst - 1) % n + 1, v = (a[i].y + lst - 1) % n + 1;
    int x = find(u), y = find(v);
    if (a[i].op == 1) {
      if (find(e[u], v)) {
        auto pps = c[x].lower_bound(y);
        c[x].erase(pps);
        pps = c[y].lower_bound(x);
        c[y].erase(pps);
        e[u].erase(v), e[v].erase(u);
      } else
        c[x].insert(y), c[y].insert(x), e[u].insert(v), e[v].insert(u);
    } else {
      dfs(x);
      if (vis[y])
        lst = 1;
      else
        lst = 0;
      putchar(lst + '0');
      for (int j = 1; j <= uu; j++) vis[use[j]] = 0;
      uu = 0;
    }
    if (i % B == 0) rebuild(i);
  }
  return 0;
}
