#include <bits/stdc++.h>
using namespace std;
int fa[400005], len[400005], dep[400005], s[400005], t[400005];
pair<int, int> q[400005];
map<pair<int, int>, int> id;
struct node {
  int u, v;
  bool delta;
};
struct edge {
  int u, v, d;
} e[800005];
vector<edge> ve[4000005];
struct linear_basis {
  int lb[35];
  inline void ins(int x) {
    for (register int i = 30; ~i; --i)
      if (x >> i & 1) {
        if (lb[i])
          x ^= lb[i];
        else {
          lb[i] = x;
          break;
        }
      }
    return;
  }
  inline int qmin(int x) {
    for (register int i = 30; ~i; --i)
      if ((x ^ lb[i]) < x) x ^= lb[i];
    return x;
  }
} lnbs;
int ff(int x) {
  if (x == fa[x]) return x;
  return ff(fa[x]);
}
int sxpfa(int x) {
  if (x == fa[x]) return 0;
  return len[x] ^ sxpfa(fa[x]);
}
void inse(int root, int l, int r, int ql, int qr, edge delta) {
  if (ql <= l && r <= qr) return (void)ve[root].push_back(delta);
  int mid = l + r >> 1;
  if (ql <= mid) inse(root << 1, l, mid, ql, qr, delta);
  if (qr > mid) inse(root << 1 | 1, mid + 1, r, ql, qr, delta);
  return;
}
void solve(int root, int l, int r, linear_basis lnbs) {
  stack<node> sta;
  for (register int i = 0, u, v, k, fu, fv; i < ve[root].size(); ++i) {
    u = ve[root][i].u, v = ve[root][i].v, fu = ff(u), fv = ff(v),
    k = ve[root][i].d ^ sxpfa(u) ^ sxpfa(v);
    if (fu == fv)
      lnbs.ins(k);
    else {
      if (dep[fu] > dep[fv]) swap(u, v), swap(fu, fv);
      fa[fu] = fv, len[fu] = k;
      if (dep[fu] == dep[fv])
        ++dep[fv], sta.push((node){fu, fv, 1});
      else
        sta.push((node){fu, fv, 0});
    }
  }
  if (l == r)
    printf("%d\n", lnbs.qmin(sxpfa(q[l].first) ^ sxpfa(q[l].second)));
  else {
    int mid = l + r >> 1;
    solve(root << 1, l, mid, lnbs), solve(root << 1 | 1, mid + 1, r, lnbs);
  }
  while (!sta.empty()) {
    node tp = sta.top();
    len[fa[tp.u] = tp.u] = 0, dep[tp.v] -= tp.delta, sta.pop();
  }
  return;
}
int main() {
  int n, m, u, v, d, opt, qq;
  scanf("%d%d", &n, &m);
  int tim = 1, cnt = m;
  for (register int i = 1; i <= n; ++i) fa[i] = i;
  for (register int i = 1; i <= m; ++i)
    scanf("%d%d%d", &u, &v, &d),
        id[make_pair(u, v)] = i, e[i] = (edge){u, v, d}, s[i] = 1, t[i] = -1;
  scanf("%d", &qq);
  while (qq--) {
    scanf("%d%d%d", &opt, &u, &v);
    if (opt == 1)
      scanf("%d", &d), id[make_pair(u, v)] = ++cnt, s[cnt] = tim, t[cnt] = -1,
                                       e[cnt] = (edge){u, v, d};
    else if (opt == 2)
      t[id[make_pair(u, v)]] = tim - 1;
    else
      q[tim] = make_pair(u, v), ++tim;
  }
  --tim;
  for (register int i = 1; i <= cnt; ++i) t[i] == -1 ? t[i] = tim : t[i];
  for (register int i = 1; i <= cnt; ++i)
    if (s[i] <= t[i]) inse(1, 1, tim, s[i], t[i], e[i]);
  solve(1, 1, tim, lnbs);
  return 0;
}
