#include <bits/stdc++.h>
using namespace std;
int n, m, q, a[200050], fa[200050], size[200050], p[40][30], ans[200050], top;
struct node {
  int u, v, w;
  bool operator<(const node &x) const {
    if (u == x.u) {
      if (v == x.v) return w < x.w;
      return v < x.v;
    }
    return u < x.u;
  }
} qu[200050];
map<node, int> app;
vector<node> ch[200050 << 2];
pair<int *, int> st[200050 << 2];
void ins(int u, int l, int r, int tl, int tr, node x) {
  if (tl <= l && r <= tr) return ch[u].push_back(x);
  if (tl <= ((l + r) >> 1)) ins(u << 1, l, ((l + r) >> 1), tl, tr, x);
  if (((l + r) >> 1) < tr) ins(u << 1 | 1, ((l + r) >> 1) + 1, r, tl, tr, x);
}
pair<int, int> get(int u) {
  int d = 0;
  while (u ^ fa[u]) d ^= a[u], u = fa[u];
  return make_pair(u, d);
}
int merge(int u, int v, int w) {
  int ret = 0;
  if (size[u] < size[v]) swap(u, v);
  if (size[u] == size[v]) {
    st[++top] = make_pair(&size[u], size[u]);
    ++size[u], ++ret;
  }
  st[++top] = make_pair(&fa[v], fa[v]), fa[v] = u, ++ret;
  st[++top] = make_pair(&a[v], a[v]), a[v] = w, ++ret;
  return ret;
}
void add(int w, int d) {
  for (register int i = 30; ~i; --i) {
    if ((1 << i) & w) {
      if (!p[i][d])
        return void(p[i][d] = w);
      else
        w ^= p[i][d];
    }
  }
}
int calc(int w, int d) {
  for (register int i = 30; ~i; --i) {
    if ((1 << i) & w) w ^= p[i][d];
  }
  return w;
}
void solve(int u, int l, int r, int d) {
  int tms = 0;
  for (register int i = 0; i <= 31; ++i) p[i][d] = p[i][d - 1];
  for (auto p : ch[u]) {
    pair<int, int> x = get(p.u), y = get(p.v);
    if (x.first != y.first)
      tms += merge(x.first, y.first, p.w ^ x.second ^ y.second);
    else
      add(p.w ^ x.second ^ y.second, d);
  }
  if (l == r)
    ans[qu[l].w] = calc(get(qu[l].u).second ^ get(qu[l].v).second, d);
  else
    solve(u << 1, l, ((l + r) >> 1), d + 1),
        solve(u << 1 | 1, ((l + r) >> 1) + 1, r, d + 1);
  while (tms--) {
    *(st[top].first) = st[top].second;
    --top;
  }
}
int main() {
  int u, v, w;
  scanf("%d%d", &n, &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, &w);
    if (u > v) swap(u, v);
    app[node{u, v, w}] = 1;
  }
  scanf("%d", &q);
  int opt;
  for (register int i = 1; i <= q; ++i) {
    scanf("%d%d%d", &opt, &u, &v);
    if (u > v) swap(u, v);
    if (opt == 1) {
      scanf("%d", &w);
      app[node{u, v, w}] = i;
    } else if (opt == 2) {
      map<node, int>::iterator it = app.lower_bound(node{u, v, 0});
      ins(1, 1, q, it->second, i, it->first), app.erase(it);
    } else
      qu[i] = node{u, v, i};
  }
  for (auto u : app) ins(1, 1, q, u.second, q, u.first);
  memset(ans, -1, sizeof(ans));
  solve(1, 1, q, 1);
  for (register int i = 1; i <= q; ++i)
    if (ans[i] != -1) cout << ans[i] << endl;
  return 0;
}
