#include <bits/stdc++.h>
const int oo = 2139063143;
const int N = 1010000;
const int P = 1000000007;
using namespace std;
inline void sc(int &x) {
  x = 0;
  static int p;
  p = 1;
  static char c;
  c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - 48);
    c = getchar();
  }
  x *= p;
}
inline void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
inline void pr(int x) { print(x), putchar('\n'); }
int b[35];
int ins(int x) {
  for (int i = 30; i >= 0; i--)
    if (x >> i & 1) {
      if (!b[i]) {
        b[i] = x;
        return i;
      }
      x ^= b[i];
    }
  return 33;
}
int query(int x) {
  for (int i = 30; i >= 0; i--) x = min(x, x ^ b[i]);
  return x;
}
int fa[N], dis[N], siz[N];
int getdis(int &x) {
  int ans = 0;
  while (x != fa[x]) ans ^= dis[x], x = fa[x];
  return ans;
}
struct LY {
  int x, y, w;
};
vector<LY> v[N << 2];
int vis[N];
int ax[N], ay[N];
void update(int p, int L, int R, int l, int r, LY x) {
  if (l <= L && R <= r) {
    v[p].push_back(x);
    return;
  }
  int mid = (L + R) >> 1, ls = p << 1, rs = ls | 1;
  if (l <= mid) update(ls, L, mid, l, r, x);
  if (r > mid) update(rs, mid + 1, R, l, r, x);
}
int ans[N];
int st[N], z;
void del(int l) {
  while (z >= l) b[st[z--]] = 0;
}
int xx[N], yy[N], zz;
void dell(int l) {
  while (zz >= l)
    siz[fa[xx[zz]]] -= siz[xx[zz]], fa[xx[zz]] = xx[zz], dis[xx[zz]] = 0, --zz;
}
void solve(int p, int l, int r) {
  if (!(vis[r] - vis[l - 1])) return;
  int he1 = z + 1, he2 = zz + 1;
  for (int i = 0; i < (int)v[p].size(); i++) {
    int x = v[p][i].x, y = v[p][i].y, w = v[p][i].w;
    int dx = getdis(x), dy = getdis(y);
    if (x == y) {
      st[++z] = ins(dx ^ dy ^ w);
      continue;
    }
    if (siz[x] > siz[y]) swap(x, y), swap(dx, dy);
    fa[x] = y, dis[x] = dx ^ dy ^ w, siz[y] += siz[x];
    xx[++zz] = x, yy[zz] = y;
  }
  if (l == r) {
    int dx = getdis(ax[l]), dy = getdis(ay[l]);
    ans[l] = query(dx ^ dy);
    del(he1), dell(he2);
    return;
  }
  int mid = (l + r) >> 1, ls = p << 1, rs = ls | 1;
  solve(ls, l, mid);
  solve(rs, mid + 1, r);
  del(he1);
  dell(he2);
}
map<pair<int, int>, int> mp;
int las[N], su[N], sv[N];
int w[N], totw = 0;
int main() {
  int n, m;
  sc(n), sc(m);
  for (int i = 1; i <= n; i++) fa[i] = i, siz[i] = 1;
  for (int i = 1; i <= m; i++) {
    int u, v;
    sc(u), sc(v), sc(w[i]);
    mp[make_pair(u, v)] = i;
    su[i] = u, sv[i] = v;
  }
  totw = m;
  int q;
  sc(q);
  for (int i = 1; i <= q; i++) {
    int op, u, v;
    sc(op), sc(u), sc(v);
    if (op == 1)
      sc(w[++totw]), mp[make_pair(u, v)] = totw, las[totw] = i, su[totw] = u,
                                     sv[totw] = v;
    if (op == 2) {
      int bh = mp[make_pair(u, v)];
      update(1, 0, q, las[bh], i - 1, (LY){u, v, w[bh]}), las[bh] = -1;
    }
    if (op == 3) ++vis[i], ax[i] = u, ay[i] = v;
  }
  for (int i = 1; i <= totw; i++)
    if (las[i] != -1) update(1, 0, q, las[i], q, (LY){su[i], sv[i], w[i]});
  for (int i = 1; i <= q; i++) vis[i] += vis[i - 1];
  memset(ans, -1, sizeof(int) * (q + 1));
  solve(1, 0, q);
  for (int i = 1; i <= q; i++)
    if (ans[i] != -1) pr(ans[i]);
  return 0;
}
