#include <bits/stdc++.h>
using namespace std;
const int N = 400000 + 10;
using PII = pair<int, int>;
struct Base {
  int p[31];
  void ins(int x) {
    for (int j = 30; ~j; --j)
      if ((x >> j) & 1) {
        if (!p[j]) {
          p[j] = x;
          return;
        }
        x ^= p[j];
      }
  }
  int ask(int x) {
    for (int j = 30; ~j; --j) x = min(x, x ^ p[j]);
    return x;
  }
} S;
int st[N << 1], top, f[N], val[N], d[N];
void init(int n) {
  for (int i = 1; i <= n; i++) f[i] = i, val[i] = 0, d[i] = 1;
  top = 0;
}
int sf(int x) { return f[x] == x ? x : sf(f[x]); }
int ask(int x) {
  int res = 0;
  for (; x != f[x]; x = f[x]) res ^= val[x];
  return res;
}
void back(int tag) {
  for (; top != tag; top--) {
    if (st[top] < 0)
      d[-st[top]]--;
    else {
      f[st[top]] = st[top];
      val[st[top]] = 0;
    }
  }
}
void Union(int x, int y, int _val) {
  if (d[x] > d[y]) swap(x, y);
  if (d[x] == d[y]) d[y]++, st[++top] = -y;
  f[x] = y;
  val[x] = _val;
  st[++top] = x;
}
struct data1 {
  int x, y, w, l, r;
} E[N];
struct data2 {
  int x, y;
} Q[N];
vector<int> v[N << 1];
int idx(int l, int r) { return l + r | l != r; }
void upd(int l, int r, int y) {
  int x = idx(l, r), mid = (l + r) >> 1;
  if (E[y].l <= l && r <= E[y].r) {
    v[x].push_back(y);
    return;
  }
  if (E[y].l <= mid) upd(l, mid, y);
  if (E[y].r > mid) upd(mid + 1, r, y);
}
void dfs(int l, int r, Base S) {
  int x = idx(l, r), t = top, mid = (l + r) >> 1;
  for (auto y : v[x]) {
    int fx = sf(E[y].x), fy = sf(E[y].y);
    int dx = ask(E[y].x), dy = ask(E[y].y);
    if (fx == fy) {
      S.ins(dx ^ dy ^ E[y].w);
      continue;
    }
    Union(fx, fy, dx ^ dy ^ E[y].w);
  }
  if (l == r) {
    int dx = ask(Q[l].x), dy = ask(Q[l].y);
    printf("%d\n", S.ask(dx ^ dy));
    back(t);
    return;
  }
  dfs(l, mid, S);
  dfs(mid + 1, r, S);
  back(t);
}
map<PII, int> id;
int n, m, x, y, z, q, op, tot;
int main() {
  scanf("%d%d", &n, &m);
  init(n);
  tot = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    if (x > y) swap(x, y);
    E[i] = {x, y, z, tot + 1, -1};
    id[{x, y}] = i;
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d%d", &x, &y, &z);
      if (x > y) swap(x, y);
      E[++m] = {x, y, z, tot + 1, -1};
      id[{x, y}] = m;
    } else if (op == 2) {
      scanf("%d%d", &x, &y);
      if (x > y) swap(x, y);
      E[id[{x, y}]].r = tot;
    } else {
      scanf("%d%d", &x, &y);
      Q[++tot] = {x, y};
    }
  }
  for (int i = 1; i <= m; i++) {
    if (E[i].r == -1) E[i].r = tot;
    if (E[i].l <= E[i].r) upd(1, tot, i);
  }
  dfs(1, tot, S);
  return 0;
}
