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 + 5;
const double pi = acos(-1);
int p[N];
int f[N];
int h[N];
stack<pair<int*, int> > ops;
int base[30];
void app(int* a, int v) {
  ops.push(make_pair(a, *a));
  *a = v;
}
void add(int x) {
  for (int i = 29; i >= 0; --i)
    if (base[i] >= 0)
      if (x >> i & 1) x ^= base[i];
  if (x == 0) return;
  for (int i = 29; i >= 0; --i)
    if (x >> i & 1) {
      app(base + i, x);
      return;
    }
}
pair<int, int> lead(int x) {
  int v = 0;
  while (x != p[x]) {
    v ^= f[x];
    x = p[x];
  }
  return pair<int, int>(x, v);
}
void join(int x, int y, int d) {
  pair<int, int> pa = lead(x);
  d ^= pa.second;
  pair<int, int> emplace_back = lead(y);
  d ^= emplace_back.second;
  if (pa.first == emplace_back.first) {
    add(d);
    return;
  }
  if (h[pa.first] < h[emplace_back.first]) swap(pa, emplace_back);
  if (h[pa.first] == h[emplace_back.first]) app(h + pa.first, h[pa.first] + 1);
  app(p + emplace_back.first, pa.first);
  app(f + emplace_back.first, d);
}
vector<pair<int, pair<int, int> > > Que[N << 2];
void add(int i, int l, int r, int L, int R, pair<int, pair<int, int> > v) {
  if (l > R) return;
  if (L > r) return;
  if (L <= l && r <= R) {
    Que[i].emplace_back(v);
    return;
  }
  int m = (l + r) / 2;
  add(i << 1, l, m, L, R, v);
  ++m;
  add(i << 1 | 1, m, r, L, R, v);
}
int t[N];
int a[N];
int b[N];
void cal(int i, int l, int r) {
  int len = (int)ops.size();
  for (pair<int, pair<int, int> > E : Que[i]) {
    int x = E.second.first;
    int y = E.second.second;
    int d = E.first;
    join(x, y, d);
  }
  if (l == r) {
    if (t[l] == 3) {
      int val = lead(a[l]).second ^ lead(b[l]).second;
      for (int i = 29; i >= 0; --i)
        if (base[i] >= 0 && (val >> i & 1)) val ^= base[i];
      cout << val << "\n";
    }
  } else {
    int m = (l + r) / 2;
    cal(i << 1, l, m);
    ++m;
    cal(i << 1 | 1, m, r);
  }
  while ((int)ops.size() > len) {
    *ops.top().first = ops.top().second;
    ops.pop();
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int m;
  cin >> m;
  map<pair<int, int>, pair<int, int> > mp;
  for (int i = 0; i < m; ++i) {
    int x;
    cin >> x;
    int y;
    cin >> y;
    int d;
    cin >> d;
    if (x > y) swap(x, y);
    mp[pair<int, int>(x, y)] = pair<int, int>(d, 0);
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    cin >> t[i];
    cin >> a[i];
    cin >> b[i];
    pair<int, int> e(a[i], b[i]);
    if (e.first > e.second) swap(e.first, e.second);
    if (t[i] == 1) {
      int c;
      cin >> c;
      mp[e] = pair<int, int>(c, i);
    }
    if (t[i] == 2) {
      add(1, 1, q, mp[e].second, i, pair<int, pair<int, int> >(mp[e].first, e));
      mp.erase(e);
    }
  }
  for (auto it : mp)
    add(1, 1, q, it.second.second, q,
        pair<int, pair<int, int> >(it.second.first, it.first));
  fill(base, base + 30, -1);
  iota(p + 1, p + 1 + n, 1);
  cal(1, 1, q);
}