Problem: You are given an undirected connected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed more than once, then it is included in bitwise xor the same number of times). 

There are three types of queries you have to process:

  * 1 x y d — add an edge connecting vertex x to vertex y with weight d. It is guaranteed that there is no edge connecting x to y before this query; 
  * 2 x y — remove an edge connecting vertex x to vertex y. It is guaranteed that there was such edge in the graph, and the graph stays connected after this query; 
  * 3 x y — calculate the length of the shortest path (possibly non-simple) from vertex x to vertex y. 



Print the answers for all queries of type 3.

Input

The first line contains two numbers n and m (1 ≤ n, m ≤ 200000) — the number of vertices and the number of edges in the graph, respectively.

Then m lines follow denoting the edges of the graph. Each line contains three integers x, y and d (1 ≤ x < y ≤ n, 0 ≤ d ≤ 230 - 1). Each pair (x, y) is listed at most once. The initial graph is connected.

Then one line follows, containing an integer q (1 ≤ q ≤ 200000) — the number of queries you have to process.

Then q lines follow, denoting queries in the following form:

  * 1 x y d (1 ≤ x < y ≤ n, 0 ≤ d ≤ 230 - 1) — add an edge connecting vertex x to vertex y with weight d. It is guaranteed that there is no edge connecting x to y before this query; 
  * 2 x y (1 ≤ x < y ≤ n) — remove an edge connecting vertex x to vertex y. It is guaranteed that there was such edge in the graph, and the graph stays connected after this query; 
  * 3 x y (1 ≤ x < y ≤ n) — calculate the length of the shortest path (possibly non-simple) from vertex x to vertex y. 



It is guaranteed that at least one query has type 3.

Output

Print the answers for all queries of type 3 in the order they appear in input.

Example

Input

5 5
1 2 3
2 3 4
3 4 5
4 5 6
1 5 1
5
3 1 5
1 1 3 1
3 1 5
2 1 5
3 1 5


Output

1
1
2

Solution (in CPP):

Solution:
#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);
}