#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 5;
int n, m, q, N = 4e5;
int basis[30];
int add(int x) {
  for (int i = 29; i >= 0; --i) {
    if (x & (1 << i)) {
      if (!basis[i]) {
        basis[i] = x;
        return i;
      }
      x ^= basis[i];
    }
  }
  return -1;
}
int T, lab[maxn], dist[maxn];
vector<pair<int*, int>> data;
int FindLab(int u) { return lab[u] < 0 ? u : FindLab(lab[u]); }
int FindDist(int u) { return lab[u] < 0 ? 0 : (dist[u] ^ FindDist(lab[u])); }
void Change(int& u, int v) {
  data.push_back(make_pair(&u, u));
  u = v;
}
void rollback(int sz) {
  while (data.size() > sz) {
    (*data.back().first) = data.back().second;
    data.pop_back();
  }
}
struct edge {
  int u, v, c;
} e[maxn];
vector<int> adj[maxn * 4], qq[maxn];
void update(int x, int l, int r, int L, int R, int val) {
  if (L > r || l > R) return;
  if (L <= l && r <= R) {
    adj[x].push_back(val);
    return;
  }
  int mid = l + r >> 1;
  update(x * 2, l, mid, L, R, val);
  update(x * 2 + 1, mid + 1, r, L, R, val);
}
int Query(int u, int v) {
  int res = (FindDist(u) ^ FindDist(v));
  for (int i = 29; i >= 0; --i) {
    if (res > (res ^ basis[i])) res ^= basis[i];
  }
  return res;
}
int Merge(int u, int v, int c) {
  int du = FindDist(u);
  int dv = FindDist(v);
  u = FindLab(u);
  v = FindLab(v);
  c ^= du ^ dv;
  if (u == v) return add(c);
  if (lab[u] > lab[v]) swap(u, v);
  Change(lab[u], lab[u] + lab[v]);
  Change(lab[v], u);
  Change(dist[v], c);
  return -1;
}
void go(int x, int l, int r) {
  int tmp = data.size();
  vector<int> d;
  for (auto c : adj[x]) {
    d.push_back(Merge(e[c].u, e[c].v, e[c].c));
  }
  if (l == r) {
    for (auto c : qq[l]) {
      cout << Query(e[c].u, e[c].v) << '\n';
    }
  } else {
    int mid = l + r >> 1;
    go(x * 2, l, mid);
    go(x * 2 + 1, mid + 1, r);
  }
  for (auto& c : d)
    if (c != -1) basis[c] = 0;
  rollback(tmp);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("A"
            ".INP",
            "r")) {
    freopen(
        "A"
        ".INP",
        "r", stdin);
    freopen(
        "A"
        ".OUT",
        "w", stdout);
  }
  fill_n(lab, maxn, -1);
  map<pair<int, int>, int> mmap;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> e[i].u >> e[i].v >> e[i].c;
    mmap[make_pair(e[i].u, e[i].v)] = i;
  }
  cin >> q;
  N = q + m;
  for (int i = m + 1; i <= q + m; ++i) {
    int type;
    cin >> type;
    if (type == 1) {
      cin >> e[i].u >> e[i].v >> e[i].c;
      mmap[make_pair(e[i].u, e[i].v)] = i;
    } else if (type == 2) {
      cin >> e[i].u >> e[i].v;
      update(1, 1, N, mmap[make_pair(e[i].u, e[i].v)], i,
             mmap[make_pair(e[i].u, e[i].v)]);
      mmap[make_pair(e[i].u, e[i].v)] = 0;
    } else {
      cin >> e[i].u >> e[i].v;
      e[i].c = -1;
      qq[i].push_back(i);
    }
  }
  for (auto& c : mmap) {
    if (c.second) {
      update(1, 1, N, c.second, N, c.second);
    }
  }
  go(1, 1, N);
}
