#include <bits/stdc++.h>
using namespace std;
struct edge {
  int x, y, w, l, r;
} e[400010];
struct node {
  int x, y, w, fx, fy, rx, ry;
};
struct ask {
  int x, y;
} q[200010];
int n, m, Q, fa[200010], d[200010], rk[200010], p[25][35];
map<pair<int, int>, int> mp;
vector<node> v[1600010];
void ins(int k, int l, int r, int x, int y, int t) {
  if (l == x && r == y) {
    v[k].push_back((node){e[t].x, e[t].y, e[t].w, 0, 0});
    return;
  }
  int mid = (l + r) >> 1;
  if (x > mid) {
    ins(k << 1 | 1, mid + 1, r, x, y, t);
  } else if (y <= mid) {
    ins(k << 1, l, mid, x, y, t);
  } else {
    ins(k << 1, l, mid, x, mid, t);
    ins(k << 1 | 1, mid + 1, r, mid + 1, y, t);
  }
}
int find(int x, int &y) {
  y = 0;
  while (fa[x] != x) {
    y ^= d[x];
    x = fa[x];
  }
  return x;
}
void Union(int x, int y, int w) {
  if (rk[x] == rk[y]) {
    fa[x] = y;
    d[x] = w;
    rk[y]++;
  } else if (rk[x] < rk[y]) {
    fa[x] = y;
    d[x] = w;
  } else {
    fa[y] = x;
    d[y] = w;
  }
}
void add(int t, int x) {
  for (int i = 29; i >= 0; i--) {
    if (!(x & (1 << i))) {
      continue;
    }
    if (!p[t][i]) {
      p[t][i] = x;
      return;
    }
    x ^= p[t][i];
  }
}
int get(int x, int t) {
  for (int i = 29; i >= 0; i--) {
    if ((x ^ p[t][i]) < x) {
      x ^= p[t][i];
    }
  }
  return x;
}
void work(int k, int l, int r, int t) {
  for (int i = 0; i < v[k].size(); i++) {
    int x = v[k][i].x;
    int y = v[k][i].y;
    int w = v[k][i].w;
    int a, b, fx, fy;
    fx = find(x, a);
    fy = find(y, b);
    if (fx == fy) {
      add(t, w ^ a ^ b);
      continue;
    }
    v[k][i].fx = fx;
    v[k][i].fy = fy;
    v[k][i].rx = rk[fx];
    v[k][i].ry = rk[fy];
    Union(fx, fy, w ^ a ^ b);
  }
  if (l == r) {
    if (q[l].x) {
      int x = q[l].x;
      int y = q[l].y;
      int a, b;
      find(x, a);
      find(y, b);
      printf("%d\n", get(a ^ b, t));
    }
  } else {
    int mid = (l + r) >> 1;
    for (int i = 0; i < 30; i++) {
      p[t + 1][i] = p[t][i];
    }
    work(k << 1, l, mid, t + 1);
    for (int i = 0; i < 30; i++) {
      p[t + 1][i] = p[t][i];
    }
    work(k << 1 | 1, mid + 1, r, t + 1);
  }
  for (int i = (int)v[k].size() - 1; i >= 0; i--) {
    if (!v[k][i].fx) {
      continue;
    }
    int x = v[k][i].fx;
    int y = v[k][i].fy;
    fa[x] = x;
    fa[y] = y;
    d[x] = d[y] = 0;
    rk[x] = v[k][i].rx;
    rk[y] = v[k][i].ry;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].w);
    if (e[i].x > e[i].y) {
      swap(e[i].x, e[i].y);
    }
    e[i].l = 0;
    mp[make_pair(e[i].x, e[i].y)] = i;
  }
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int op, x, y, w;
    scanf("%d%d%d", &op, &x, &y);
    if (x > y) {
      swap(x, y);
    }
    if (op == 1) {
      scanf("%d", &w);
      m++;
      e[m].x = x;
      e[m].y = y;
      e[m].w = w;
      e[m].l = i;
      mp[make_pair(x, y)] = m;
    } else if (op == 2) {
      int tmp = mp[make_pair(x, y)];
      if (!tmp) {
        continue;
      }
      e[tmp].r = i;
      mp[make_pair(x, y)] = 0;
    } else {
      q[i] = (ask){x, y};
    }
  }
  for (int i = 1; i <= m; i++) {
    if (!e[i].r) {
      e[i].r = Q + 1;
    }
    ins(1, 0, Q + 1, e[i].l, e[i].r, i);
  }
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    rk[i] = 1;
  }
  work(1, 0, Q + 1, 0);
  return 0;
}
