#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
int n, m, Q, qn, p[110], fa[maxn], dep[maxn], val[maxn], pos[maxn], lst[maxn],
    ans[maxn], cnt, head[maxn], tot;
map<pair<int, int>, int> mp;
struct Edge {
  int x, y, w;
} e[maxn << 1], q[maxn << 2];
vector<Edge> G[maxn << 2];
vector<Edge>::iterator it;
inline int read() {
  register int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0';
  return (f == 1) ? x : -x;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
void build(int l, int r, int rt) {
  if (l == r) return pos[l] = rt, void();
  int mid = (l + r) >> 1;
  build(l, mid, (rt << 1));
  build(mid + 1, r, (rt << 1 | 1));
}
void update(int L, int R, Edge C, int l, int r, int rt) {
  if (L <= l && r <= R) return G[rt].push_back(C), void();
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, C, l, mid, (rt << 1));
  if (R > mid) update(L, R, C, mid + 1, r, (rt << 1 | 1));
}
inline int find(int x) {
  while (x != fa[x]) x = fa[x];
  return x;
}
inline int ask(int x) {
  int ans = 0;
  while (x != fa[x]) ans ^= val[x], x = fa[x];
  return ans;
}
inline int insert(int x) {
  for (int i = 29; i >= 0; i--) {
    if (!(x & (1 << i))) continue;
    if (!p[i]) return p[i] = x, i;
    x ^= p[i];
  }
  return -1;
}
inline int query(int x, int y) {
  int z = ask(x) ^ ask(y);
  for (int i = 29; i >= 0; i--)
    if (p[i] && (z & (1 << i))) z ^= p[i];
  return z;
}
void solve(int l, int r, int rt) {
  vector<int> rub;
  vector<Edge> del;
  int x, y, w, u, v, d;
  for (it = G[rt].begin(); it != G[rt].end(); it++) {
    x = it->x;
    y = it->y;
    w = it->w;
    u = find(x);
    v = find(y);
    if (u == v) {
      d = insert(ask(x) ^ ask(y) ^ w);
      if (d >= 0) rub.push_back(d);
    } else {
      if (dep[u] > dep[v]) swap(u, v);
      val[u] = ask(x) ^ ask(y) ^ w;
      fa[u] = v;
      del.push_back((Edge){u, v, dep[v]});
      if (dep[u] == dep[v]) dep[v]++;
    }
  }
  int mid = (l + r) >> 1;
  if (l == r) {
    if (q[rt].x) ans[q[rt].w] = query(q[rt].x, q[rt].y);
  } else
    solve(l, mid, (rt << 1)), solve(mid + 1, r, (rt << 1 | 1));
  reverse(del.begin(), del.end());
  for (it = del.begin(); it != del.end(); it++) {
    u = it->x;
    v = it->y;
    val[u] = 0;
    fa[u] = u;
    dep[v] = it->w;
  }
  for (int i = rub.size() - 1; i >= 0; i--) p[rub[i]] = 0;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) fa[i] = i;
  int op, x, y, w;
  for (int i = 1; i <= m; i++) {
    x = read(), y = read(), w = read();
    mp[make_pair(x, y)] = ++cnt;
    e[cnt] = (Edge){x, y, w};
  }
  Q = read();
  build(0, Q, 1);
  for (int i = 1; i <= Q; i++) {
    op = read(), x = read(), y = read();
    if (x > y) swap(x, y);
    if (op == 1)
      w = read(), mp[make_pair(x, y)] = ++cnt, lst[cnt] = i,
      e[cnt] = (Edge){x, y, w};
    if (op == 2)
      w = mp[make_pair(x, y)], update(lst[w], i - 1, e[w], 0, Q, 1),
      lst[w] = -1, mp[make_pair(x, y)] = 0;
    if (op == 3) q[pos[i]] = (Edge){x, y, ++qn};
  }
  for (int i = 1; i <= cnt; i++)
    if (lst[i] >= 0) update(lst[i], Q, e[i], 0, Q, 1);
  solve(0, Q, 1);
  for (int i = 1; i <= qn; i++) print(ans[i]), putchar('\n');
  return 0;
}
