#include <bits/stdc++.h>
using namespace std;
int const N = 100000, K = 7000;
bitset<K> a[N + 1], ori[K + 1], kl[K + 1];
vector<int> dv[K + 1];
int main() {
  for (int i = 1; i < (int)(K + 1); ++i)
    for (int j = i << 1; j <= K; j += i) dv[j].push_back(i);
  for (int i = K; i > 0; --i) {
    kl[i][i] = true;
    for (int j = i << 1; j <= K; j += i) kl[i] ^= kl[j];
  }
  for (int i = 1; i < (int)(K + 1); ++i) {
    ori[i][i] = true;
    for (int j = 0; j < (int)(dv[i].size()); ++j) ori[i][dv[i][j]] = true;
  }
  int n, q;
  scanf("%d%d", &n, &q);
  string an;
  while (q--) {
    int o;
    scanf("%d", &o);
    if (o == 1) {
      int x, v;
      scanf("%d%d", &x, &v);
      a[x] = ori[v];
    } else if (o == 2) {
      int x, y, z;
      scanf("%d%d%d", &x, &y, &z);
      a[x] = a[y] ^ a[z];
    } else if (o == 3) {
      int x, y, z;
      scanf("%d%d%d", &x, &y, &z);
      a[x] = a[y] & a[z];
    } else {
      int x, v;
      scanf("%d%d", &x, &v);
      bool p = (a[x] & kl[v]).count() & 1;
      an += '0' + p;
    }
  }
  printf("%s\n", an.c_str());
}
