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 N = 2e5 + 7;
struct UFS {
  stack<pair<int, int> > stk;
  int f[N], siz[N], dis[N];
  void init(int x) {
    for (int i = 1, iE = x; i <= iE; i++) siz[i] = 1, f[i] = i, dis[i] = 0;
  }
  int find(int x) { return f[x] == x ? x : find(f[x]); }
  int getsum(int x) { return f[x] == x ? 0 : getsum(f[x]) ^ dis[x]; }
  int Merge(int x, int y, int len) {
    while (x ^ f[x]) len ^= dis[x], x = f[x];
    while (y ^ f[y]) len ^= dis[y], y = f[y];
    if (x == y) return 0;
    if (siz[x] > siz[y]) swap(x, y);
    stk.push(make_pair(x, siz[x])), f[x] = y, dis[x] = len, siz[y] += siz[x];
    return 1;
  }
  void revoke() {
    int u = stk.top().first;
    siz[f[u]] -= stk.top().second, f[u] = u, stk.pop();
  }
} ufs;
int G[N << 2][30];
void Ins(int id, int x) {
  for (int i = 29, iE = 0; i >= iE; i--)
    if ((x >> i) & 1) {
      if (!G[id][i]) G[id][i] = x;
      x ^= G[id][i];
    }
}
int get(int id, int x) {
  for (int i = 29, iE = 0; i >= iE; i--)
    if ((x ^ G[id][i]) < x) x ^= G[id][i];
  return x;
}
void copy(int x, int y) {
  for (int i = 0, iE = 29; i <= iE; i++) G[y][i] = G[x][i];
}
int n, m, q, tot, FR[N], TO[N];
struct node {
  int u, v, l, r, val;
} e[N << 1];
vector<int> ve[N << 2];
void ins(int id, int L, int R, int l, int r, int val) {
  if (l <= L && R <= r) return ve[id].push_back(val), void();
  int mid = (L + R) / 2;
  if (l <= mid) ins(id << 1, L, mid, l, r, val);
  if (r > mid) ins(id << 1 | 1, mid + 1, R, l, r, val);
}
void dfs(int id, int L, int R) {
  int mid = (L + R) / 2, cnt = 0;
  for (int p : ve[id]) {
    int u = e[p].u, v = e[p].v;
    if (ufs.find(u) == ufs.find(v))
      Ins(id, ufs.getsum(u) ^ ufs.getsum(v) ^ e[p].val);
    else
      cnt += ufs.Merge(u, v, e[p].val);
  }
  if (L ^ R)
    copy(id, id << 1), copy(id, id << 1 | 1), dfs(id << 1, L, mid),
        dfs(id << 1 | 1, mid + 1, R);
  else if (FR[L] && TO[L])
    printf("%d\n", get(id, ufs.getsum(FR[L]) ^ ufs.getsum(TO[L])));
  while (cnt--) ufs.revoke();
}
unordered_map<int, int> mp[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, iE = m; i <= iE; i++) {
    ++tot;
    scanf("%d%d%d", &e[tot].u, &e[tot].v, &e[tot].val), e[tot].l = 1;
    mp[e[tot].u][e[tot].v] = mp[e[tot].v][e[tot].u] = i;
  }
  scanf("%d", &q);
  for (int i = 1, iE = q; i <= iE; i++) {
    int opt, u, v, val;
    scanf("%d%d%d", &opt, &u, &v);
    if (opt == 1)
      ++tot, scanf("%d", &e[tot].val), mp[u][v] = mp[v][u] = tot, e[tot].u = u,
                                       e[tot].v = v, e[tot].l = i;
    if (opt == 2) e[mp[u][v]].r = i, mp[u].erase(v), mp[v].erase(u);
    if (opt == 3) FR[i] = u, TO[i] = v;
  }
  for (int i = 1, iE = tot; i <= iE; i++)
    if (!e[i].r) e[i].r = q;
  for (int i = 1, iE = tot; i <= iE; i++) ins(1, 1, q, e[i].l, e[i].r, i);
  ufs.init(n);
  dfs(1, 1, q);
  return 0;
}