#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];
  return i;
}
template <typename T>
string join(const vector<T>& v) {
  stringstream s;
  for (int i = 0; i < ((int)(v).size()); ++i) s << ' ' << v[i];
  return s.str().substr(1);
}
template <typename T>
inline ostream& operator<<(ostream& o, const vector<T>& v) {
  if ((int)(v).size()) o << join(v);
  return o;
}
template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}
template <typename T1, typename T2>
inline ostream& operator<<(ostream& o, const pair<T1, T2>& v) {
  return o << v.first << "," << v.second;
}
template <typename T>
inline long long int suma(const vector<T>& a) {
  long long int res(0);
  for (auto&& x : a) res += x;
  return res;
}
const double eps = 1e-10;
const long long int LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int M = 7001;
const int MX = 100005;
bitset<M> b[M], ib[M];
bitset<M> a[MX];
int main() {
  for (int i = 1; i < M; ++i) {
    for (int j = i; j < M; j += i) b[j][i] = 1;
  }
  for (int i = 1; i < M; ++i) {
    bitset<M> t = b[i];
    ib[i][i] = 1;
    for (int j = (i)-1; j >= 0; --j)
      if (t[j]) {
        t ^= b[j];
        ib[j][i] = 1;
      }
  }
  int q;
  scanf("%*d%d", &q);
  string ans;
  for (int qi = 0; qi < (q); ++qi) {
    int ty;
    scanf("%d", &ty);
    if (ty == 1) {
      int x, v;
      scanf("%d%d", &x, &v);
      a[x] = b[v];
    }
    if (ty == 2) {
      int x, y, z;
      scanf("%d%d%d", &x, &y, &z);
      a[x] = a[y] ^ a[z];
    }
    if (ty == 3) {
      int x, y, z;
      scanf("%d%d%d", &x, &y, &z);
      a[x] = a[y] & a[z];
    }
    if (ty == 4) {
      int x, v;
      scanf("%d%d", &x, &v);
      int res = (a[x] & ib[v]).count() & 1;
      ans += '0' + res;
    }
  }
  cout << ans << endl;
  return 0;
}
