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 = 400005, D = 30;
int n, m, Q;
int ex[N], ey[N], st[N], ed[N], ew[N];
pair<int, int> q[N];
map<pair<int, int>, int> mp;
vector<int> e[N * 2];
struct LB {
  int d[D];
  LB() { memset(d, 0, sizeof(d)); }
  void ins(int x) {
    for (int i = D - 1; i >= 0; i--) {
      if (!(x >> i & 1)) continue;
      if (!d[i]) {
        d[i] = x;
        break;
      }
      x ^= d[i];
    }
  }
  int qmin(int x) const {
    for (int i = D - 1; i >= 0; i--)
      if (x >> i & 1) x ^= d[i];
    return x;
  }
};
struct DSU {
  int tp;
  int fa[N], fw[N], siz[N];
  pair<int, int> sta[N];
  int Find(int u) const {
    while (fa[u] != u) u = fa[u];
    return u;
  }
  int calc(int u) const {
    int res = 0;
    while (fa[u] != u) res ^= fw[u], u = fa[u];
    return res;
  }
  int Merge(int u, int v, int w) {
    int fu = Find(u), fv = Find(v);
    if (fu == fv) return 0;
    if (siz[fu] < siz[fv]) swap(fu, fv), swap(u, v);
    sta[++tp] = pair<int, int>(fu, fv);
    fw[fv] = calc(u) ^ calc(v) ^ w;
    fa[fv] = fu;
    siz[fu] += siz[fv];
    return 1;
  }
  void Back() {
    int fu = sta[tp].first, fv = sta[tp].second;
    tp--;
    fa[fv] = fv;
    siz[fu] -= siz[fv];
  }
  void _init() {
    for (int i = 1; i <= n; i++) fa[i] = i, siz[i] = 1;
  }
} ds;
void upd(int u, int l, int r, int ul, int ur, int x) {
  if (l >= ul && r <= ur) {
    e[u].push_back(x);
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= ul) upd(u << 1, l, mid, ul, ur, x);
  if (mid < ur) upd(u << 1 | 1, mid + 1, r, ul, ur, x);
}
void solve(int u, int l, int r, LB x) {
  int pre = ds.tp;
  for (int i = 0; i < e[u].size(); i++) {
    int id = e[u][i];
    if (!ds.Merge(ex[id], ey[id], ew[id]))
      x.ins(ds.calc(ex[id]) ^ ds.calc(ey[id]) ^ ew[id]);
  }
  if (l < r) {
    int mid = (l + r) >> 1;
    solve(u << 1, l, mid, x);
    solve(u << 1 | 1, mid + 1, r, x);
  } else if (q[l].first)
    printf("%d\n", x.qmin(ds.calc(q[l].first) ^ ds.calc(q[l].second)));
  while (ds.tp > pre) ds.Back();
}
int main() {
  int ty, x, y, z;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    ex[i] = x;
    ey[i] = y;
    ew[i] = z;
    st[mp[pair<int, int>(x, y)] = i] = 1;
    ed[i] = N;
  }
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    scanf("%d%d%d", &ty, &x, &y);
    if (ty == 1) {
      scanf("%d", &z);
      ex[m + i] = x;
      ey[m + i] = y;
      ew[m + i] = z;
      st[mp[pair<int, int>(x, y)] = m + i] = i;
      ed[m + i] = N;
    }
    if (ty == 2) ed[mp[pair<int, int>(x, y)]] = i;
    if (ty == 3) q[i] = pair<int, int>(x, y);
  }
  for (int i = 1; i <= m + Q; i++)
    if (st[i]) upd(1, 1, Q, st[i], min(ed[i], Q), i);
  ds._init();
  solve(1, 1, Q, LB());
  return 0;
}