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;
int n, m, q, tot, Q, opt, x, y, z, top;
const int N = 200010;
int fa[N], siz[N], val[N], zhan[N], p[75][35];
map<pair<int, int>, int> mp;
struct bian {
  int x, y, z, l, r;
} e[N << 1];
struct Ask {
  int x, y;
} A[N];
vector<bian> v[N << 2];
void updata(int k, int l, int r, bian e) {
  if (e.l > e.r) return;
  if (e.l <= l && r <= e.r) {
    v[k].push_back(e);
    return;
  }
  int mid = (l + r) >> 1;
  if (e.l <= mid) updata((k << 1), l, mid, e);
  if (mid + 1 <= e.r) updata(((k << 1) | 1), mid + 1, r, e);
}
int findfa(int x) { return x == fa[x] ? fa[x] : findfa(fa[x]); }
int findval(int x) { return x == fa[x] ? 0 : val[x] ^ findval(fa[x]); }
void Insert(int k, int dep) {
  bian e;
  for (int i = 0, x, y, z, fax, fay; i < v[k].size(); ++i) {
    e = v[k][i];
    x = e.x;
    y = e.y;
    fax = findfa(x);
    fay = findfa(y);
    if (fax != fay) {
      if (siz[fax] > siz[fay]) swap(x, y), swap(fax, fay);
      fa[fax] = fay;
      siz[fay] += siz[fax];
      val[fax] = findval(x) ^ findval(y) ^ e.z;
      zhan[++top] = fax;
    } else {
      z = findval(x) ^ findval(y) ^ e.z;
      for (int i = 31; i >= 0; --i)
        if ((z >> (i - 1)) & 1) {
          if (!p[dep][i]) {
            p[dep][i] = z;
            break;
          }
          z ^= p[dep][i];
        }
    }
  }
}
void reset(int to) {
  int x;
  while (top > to) {
    x = zhan[top--];
    siz[fa[x]] -= siz[x];
    val[x] = 0;
    fa[x] = x;
  }
}
void solve(int k, int l, int r, int dep) {
  int tmp = top;
  Insert(k, dep);
  if (l == r) {
    int x = A[l].x, y = A[l].y, ans = findval(x) ^ findval(y);
    for (int i = 31; i >= 1; --i) ans = min(ans, ans ^ p[dep][i]);
    printf("%d\n", ans);
    reset(tmp);
    return;
  }
  int mid = (l + r) >> 1;
  for (int i = 1; i <= 31; ++i) p[dep + 1][i] = p[dep][i];
  solve((k << 1), l, mid, dep + 1);
  for (int i = 1; i <= 31; ++i) p[dep + 1][i] = p[dep][i];
  solve(((k << 1) | 1), mid + 1, r, dep + 1);
  reset(tmp);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    e[++tot] = (bian){x, y, z, 1, -1};
    mp[pair<int, int>(x, y)] = tot;
  }
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    scanf("%d", &opt);
    if (opt == 1) {
      scanf("%d%d%d", &x, &y, &z);
      e[++tot] = (bian){x, y, z, Q + 1, -1};
      mp[pair<int, int>(x, y)] = tot;
    } else if (opt == 2) {
      scanf("%d%d", &x, &y);
      e[mp[pair<int, int>(x, y)]].r = Q;
      mp[pair<int, int>(x, y)] = 0;
    } else {
      scanf("%d%d", &x, &y);
      A[++Q] = (Ask){x, y};
    }
  }
  for (int i = 1; i <= tot; ++i)
    if (e[i].r == -1) e[i].r = Q;
  for (int i = 1; i <= tot; ++i) updata(1, 1, Q, e[i]);
  for (int i = 1; i <= n; ++i) fa[i] = i, siz[i] = 1;
  solve(1, 1, Q, 0);
  return 0;
}