#include <bits/stdc++.h>
int base[32 * 220][220];
int compute[32 * 220][220];
int multiiset[100010][220];
void init() {
  for (int i = 1; i < 32 * 220; i++) {
    (compute[i][i >> 5] |= (1 << (i & 31)));
    for (int j = 1; i * j < 32 * 220; j++)
      (base[i * j][i >> 5] |= (1 << (i & 31)));
  }
  for (int i = 32 * 220 - 1; i > 0; i--) {
    for (int j = 2; i * j < 32 * 220; j++) {
      for (int k = 0; k < 220; k++) compute[i][k] ^= compute[i * j][k];
    }
  }
}
inline int countOne(unsigned int a) {
  a = (a >> 16) ^ (a & 0xFFFF);
  a = (a >> 8) ^ (a & 0xFF);
  a = (a >> 4) ^ (a & 0xF);
  a = (a >> 2) ^ (a & 0x3);
  a = (a >> 1) ^ (a & 0x1);
  return a;
}
int main() {
  int N, Q;
  scanf("%d %d", &N, &Q);
  init();
  for (int i = 0; i < Q; i++) {
    int t, x, y, z, v;
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d %d", &x, &v);
      for (int j = 0; j < 220; j++) multiiset[x][j] = base[v][j];
    }
    if (t == 2) {
      scanf("%d %d %d", &x, &y, &z);
      for (int j = 0; j < 220; j++)
        multiiset[x][j] = multiiset[y][j] ^ multiiset[z][j];
    }
    if (t == 3) {
      scanf("%d %d %d", &x, &y, &z);
      for (int j = 0; j < 220; j++)
        multiiset[x][j] = multiiset[y][j] & multiiset[z][j];
    }
    if (t == 4) {
      z = 0;
      scanf("%d %d", &x, &v);
      for (int j = 0; j < 220; j++) z ^= (multiiset[x][j] & compute[v][j]);
      printf("%d", countOne(z));
    }
  }
  printf("\n");
  return 0;
}
