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 = 200005;
int n, m, q;
struct edge {
  int a, b;
} qu[N];
int g[N << 2][35];
int st[N << 1], en[N << 1], num, fa[N], val[N], size[N];
struct lsq {
  int a, b, v;
} e[N << 1];
int head[N], me;
map<edge, int> mp;
bool operator<(const edge &a, const edge &b) {
  return a.a < b.a || (a.b < b.b && a.a == b.a);
}
vector<int> t[N << 2];
edge ed(int a, int b) {
  edge x;
  x.a = a, x.b = b;
  return x;
}
int gtc(int x) {
  if (x == fa[x]) return 0;
  return val[x] ^ gtc(fa[x]);
}
int rt(int x) {
  if (x == fa[x]) return x;
  return rt(fa[x]);
}
int find(int pos, int x) {
  for (int i = 30; i >= 0; i--) {
    if (!(x & (1 << i))) continue;
    if (g[pos][i]) x ^= g[pos][i];
  }
  return x;
}
void insg(int pos, int x) {
  for (int i = 30; i >= 0; i--) {
    if (!x) return;
    if (!(x & (1 << i))) continue;
    if (!g[pos][i]) g[pos][i] = x;
    x ^= g[pos][i];
  }
}
void ins(int l, int r, int now, int ml, int mr, int k) {
  if (l == ml && r == mr) {
    t[now].push_back(k);
    return;
  }
  int mid = l + r >> 1;
  if (mr <= mid)
    ins(l, mid, now << 1, ml, mr, k);
  else if (ml > mid)
    ins(mid + 1, r, now << 1 | 1, ml, mr, k);
  else
    ins(l, mid, now << 1, ml, mid, k),
        ins(mid + 1, r, now << 1 | 1, mid + 1, mr, k);
}
int re[N << 1], ma;
void dfs(int l, int r, int now) {
  int np = ma;
  for (int i = 0; i <= 30; i++) g[now][i] = g[now >> 1][i];
  bool flag = 0;
  for (int i = 0; i < t[now].size(); i++) {
    if (t[now][i] == -1) {
      flag = 1;
      continue;
    }
    int k = t[now][i];
    int x = rt(e[k].a), y = rt(e[k].b);
    int kkk = e[k].v ^ gtc(e[k].a) ^ gtc(e[k].b);
    if (x == y)
      insg(now, kkk);
    else {
      if (size[y] > size[x])
        fa[x] = y, size[y] += size[x], val[x] = kkk, re[++ma] = x;
      else
        fa[y] = x, size[x] += size[y], re[++ma] = y, val[y] = kkk;
    }
  }
  if (flag) printf("%d\n", find(now, gtc(qu[l].a) ^ gtc(qu[l].b)));
  if (l == r) {
    while (np < ma) {
      int x = re[ma--];
      size[rt(x)] -= size[x];
      fa[x] = x;
      val[x] = 0;
    }
    return;
  }
  int mid = l + r >> 1;
  dfs(l, mid, now << 1);
  dfs(mid + 1, r, now << 1 | 1);
  while (np < ma) {
    int x = re[ma--];
    size[rt(x)] -= size[x];
    fa[x] = x;
    val[x] = 0;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) fa[i] = i, size[i] = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].v);
    mp[ed(e[i].a, e[i].b)] = i;
    mp[ed(e[i].b, e[i].a)] = i;
    st[i] = 1;
  }
  cin >> q;
  int a, b, c;
  num = m;
  for (int i = 1; i <= q; i++) {
    scanf("%d", &a);
    if (a == 1) {
      ++num;
      scanf("%d%d%d", &e[num].a, &e[num].b, &e[num].v);
      mp[ed(e[num].a, e[num].b)] = num;
      mp[ed(e[num].b, e[num].a)] = num;
      st[num] = i;
    }
    if (a == 2) {
      scanf("%d%d", &b, &c);
      en[mp[ed(b, c)]] = i;
    }
    if (a == 3) {
      scanf("%d%d", &qu[i].a, &qu[i].b);
      ins(1, q, 1, i, i, -1);
    }
  }
  for (int i = 1; i <= num; i++) {
    if (!en[i]) en[i] = q;
    ins(1, q, 1, st[i], en[i], i);
  }
  dfs(1, q, 1);
}