#include <bits/stdc++.h>
using namespace std;
int ans[200005], t[200005], val[200005];
pair<int, int> qu[200005];
set<pair<pair<int, int>, pair<int, int>>> s;
vector<pair<pair<int, int>, int>> aint[800005];
vector<int> cur;
int n, m;
pair<int, int> findt(int nod) {
  if (t[nod] < 0) return make_pair(nod, 0);
  pair<int, int> ans = findt(t[nod]);
  return make_pair(ans.first, ans.second ^ val[nod]);
}
int mini(int x) {
  for (auto it : cur) x = min(x, x ^ it);
  return x;
}
void add(int x) {
  for (auto it : cur) x = min(x, x ^ it);
  if (x == 0) return;
  for (auto &it : cur) it = min(it, it ^ x);
  cur.push_back(x);
}
void update(int nod, int st, int dr, int l, int r, int v, int u, int w) {
  if (r <= st || dr <= l) return;
  if (l <= st && dr <= r) {
    aint[nod].push_back(make_pair(make_pair(v, u), w));
    return;
  }
  int mij = (st + dr) / 2;
  update(nod * 2, st, mij, l, r, v, u, w);
  update(nod * 2 + 1, mij, dr, l, r, v, u, w);
}
void calc(int nod, int st, int dr) {
  vector<int> aux = cur;
  vector<pair<pair<int, int>, int>> aux2;
  pair<int, int> p1, p2;
  for (auto it : aint[nod]) {
    p1 = findt(it.first.first);
    p2 = findt(it.first.second);
    if (p1.first == p2.first)
      add(p1.second ^ p2.second ^ it.second);
    else {
      if (t[p1.first] > t[p2.first]) swap(p1, p2);
      aux2.push_back(make_pair(make_pair(p1.first, p2.first), t[p2.first]));
      t[p1.first] += t[p2.first];
      t[p2.first] = p1.first;
      val[p2.first] = p1.second ^ p2.second ^ it.second;
    }
  }
  if (st == dr - 1) {
    if (st < m)
      ans[st] = mini(findt(qu[st].first).second ^ findt(qu[st].second).second);
  } else {
    int mij = (st + dr) / 2;
    calc(nod * 2, st, mij);
    calc(nod * 2 + 1, mij, dr);
  }
  cur = aux;
  reverse(aux2.begin(), aux2.end());
  for (auto it : aux2) {
    t[it.first.second] = it.second;
    val[it.first.second] = 0;
    t[it.first.first] -= it.second;
  }
}
int main() {
  memset(t, -1, sizeof(t));
  scanf("%d%d", &n, &m);
  int i, q, tip, x, y, w;
  for (i = 0; i < m; i++) {
    scanf("%d%d%d", &x, &y, &w);
    if (x > y) swap(x, y);
    s.insert(make_pair(make_pair(x, y), make_pair(w, 0)));
  }
  scanf("%d", &q);
  m = 0;
  for (i = 1; i <= q; i++) {
    scanf("%d%d%d", &tip, &x, &y);
    if (x > y) swap(x, y);
    if (tip == 1)
      scanf("%d", &w), s.insert(make_pair(make_pair(x, y), make_pair(w, m)));
    if (tip == 2) {
      auto it = s.lower_bound(make_pair(make_pair(x, y), make_pair(0, 0)));
      update(1, 0, n, it->second.second, m, x, y, it->second.first);
      s.erase(it);
    }
    if (tip == 3) qu[m++] = make_pair(x, y);
  }
  for (auto it : s)
    update(1, 0, n, it.second.second, m, it.first.first, it.first.second,
           it.second.first);
  calc(1, 0, n);
  for (i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}
