#include <bits/stdc++.h>
using namespace std;
const int msk = (1 << 20) - 1;
bool debug = false;
vector<int> vt;
vector<long long> s;
int rep[210000], fa[210000];
int cnt[410000], con[410000];
int hea[210000], nex[410000], vv[410000], uu[410000];
char ret[210000];
int fin(int u) {
  if (debug) {
    printf("%s\n", __func__);
  }
  if (fa[u] != u) {
    fa[u] = fin(fa[u]);
  }
  return fa[u];
}
void join(int u, int v) {
  if (debug) {
    printf("%s\n", __func__);
  }
  u = fin(u);
  v = fin(v);
  if (u > v) {
    swap(u, v);
  }
  fa[v] = u;
}
int ee;
void add(int e) {
  if (debug) {
    printf("%s\n", __func__);
  }
  int u = (s[e] & msk);
  int v = (s[e] >> 20);
  u = rep[u];
  v = rep[v];
  if (u == v) {
    return;
  }
  if (debug) {
    printf("u %d heaU %d\n", u, hea[u]);
  }
  for (int i = hea[u]; i != -1; i = nex[i]) {
    if (uu[i] == e) {
      return;
    }
  }
  ++ee;
  vv[ee] = v;
  uu[ee] = e;
  nex[ee] = hea[u];
  hea[u] = ee;
  ++ee;
  vv[ee] = u;
  uu[ee] = e;
  nex[ee] = hea[v];
  hea[v] = ee;
}
int vis[410000], q[410000];
int ask(int u, int v) {
  if (debug) {
    printf("%s\n", __func__);
  }
  u = rep[u];
  v = rep[v];
  if (u == v) {
    return 1;
  }
  static int cur = 0;
  cur++;
  int hh = 0, tt = 0;
  q[tt++] = u;
  vis[u] = cur;
  while (hh < tt) {
    int x = q[hh++];
    for (int e = hea[x]; e != -1; e = nex[e]) {
      if (!con[uu[e]]) {
        continue;
      }
      int y = vv[e];
      if (vis[y] == cur) {
        continue;
      }
      if (y == v) {
        return 1;
      }
      q[tt++] = y;
      vis[y] = cur;
    }
  }
  return 0;
}
int n;
void gao(int l, int r) {
  if (debug) {
    printf("n %d\n", n);
  }
  if (debug) {
    printf("%s\n", __func__);
  }
  int ll = l, rr = r;
  int m = s.size();
  ee = 0;
  for (int i = 0; i < m; ++i) {
    cnt[i] = con[i] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    hea[i] = -1;
    fa[i] = i;
  }
  for (int i = ll; i < rr; i += 4) {
    if (vt[i] == 2) {
      continue;
    }
    cnt[vt[i + 3]]++;
  }
  for (int i = 0; i < ll; i += 4) {
    if (vt[i] == 2) {
      continue;
    }
    if (vt[i + 3] == -1) {
      continue;
    }
    con[vt[i + 3]] ^= 1;
  }
  for (int i = 0; i < ll; i += 4) {
    if (vt[i] == 2) {
      continue;
    }
    if (vt[i + 3] == -1) {
      continue;
    }
    if (cnt[vt[i + 3]]) {
      continue;
    }
    if (con[vt[i + 3]]) {
      join(vt[i + 1], vt[i + 2]);
    }
  }
  int pp = 0;
  for (int i = 1; i <= n; ++i) {
    int x = fin(i);
    if (x == i) {
      rep[i] = ++pp;
    } else {
      rep[i] = rep[x];
    }
  }
  for (int i = 0; i < ll; i += 4) {
    if (vt[i] == 2) {
      continue;
    }
    if (vt[i + 3] == -1) {
      continue;
    }
    if (!cnt[vt[i + 3]]) {
      continue;
    }
    if (con[vt[i + 3]]) {
      add(vt[i + 3]);
      if (debug) {
        printf("%s\n", "add_done");
      }
    }
  }
  static int tt = 0;
  static int pre = 0;
  for (int i = ll; i < rr; i += 8) {
    int ii = i + 4 * pre;
    if (vt[ii] == 2) {
      pre = ask(vt[ii + 1], vt[ii + 2]);
      ret[tt++] = char('0' + pre);
    } else {
      vt[(ii ^ 4) + 3] = -1;
      con[vt[ii + 3]] ^= 1;
      if (con[vt[ii + 3]]) {
        add(vt[ii + 3]);
        if (debug) {
          printf("%s\n", "add_done");
        }
      }
    }
  }
}
int main() {
  int m;
  cin >> n >> m;
  int a, b, c;
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d", &a, &b, &c);
    for (int i = 0; i < 2; ++i) {
      vt.emplace_back(a);
      vt.emplace_back((b + i - 1 + n) % n + 1);
      vt.emplace_back((c + i - 1 + n) % n + 1);
      vt.emplace_back(0);
    }
  }
  int u, v;
  long long uv;
  for (int i = 0; i < vt.size(); i += 4) {
    if (vt[i] == 2) {
      continue;
    }
    u = vt[i + 1];
    v = vt[i + 2];
    if (u > v) {
      swap(u, v);
    }
    long long uv = u;
    uv <<= 20;
    uv |= v;
    s.emplace_back(uv);
  }
  sort(s.begin(), s.end());
  int len = unique(s.begin(), s.end()) - s.begin();
  s.resize(len);
  for (int i = 0; i < vt.size(); i += 4) {
    if (vt[i] == 2) {
      continue;
    }
    u = vt[i + 1];
    v = vt[i + 2];
    if (u > v) {
      swap(u, v);
    }
    long long uv = u;
    uv <<= 20;
    uv |= v;
    int pos = lower_bound(s.begin(), s.end(), uv) - s.begin();
    vt[i + 3] = pos;
  }
  const int k = sqrt(m + 0.5);
  for (int i = 0; i < vt.size(); i += 8 * k) {
    int l = i, r = i + 8 * k;
    if (r > vt.size()) {
      r = vt.size();
    }
    gao(l, r);
  }
  printf("%s\n", ret);
  return 0;
}
