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>
struct MI {
 private:
  char bb[4096];
  FILE *f;
  char *bs, *be;
  char e;
  bool o, l;

 public:
  MI() : f(stdin) {}
  MI(FILE *f) : f(f), bs(0), be(0) {}
  MI(const char *s) : f(fmemopen(const_cast<char *>(s), strlen(s), "r")) {}
  inline operator bool() { return !l; }
  inline char get() {
    if (o) {
      o = 0;
      return e;
    }
    if (bs == be) be = (bs = bb) + fread(bb, 1, sizeof(bb), f);
    if (bs == be) {
      l = 1;
      return -1;
    };
    return *bs++;
  }
  inline void unget(char c) {
    o = 1;
    e = c;
  }
  template <typename T>
  inline T read() {
    T r;
    *this > r;
    return r;
  }
  template <typename T>
  inline MI &operator>(T &);
};
template <typename T>
struct Q {
  const static bool U = T(-1) >= T(0);
  inline void operator()(MI &t, T &r) const {
    r = 0;
    char c;
    bool y = 0;
    if (U)
      for (;;) {
        c = t.get();
        if (c == -1) goto E;
        if (isdigit(c)) break;
      }
    else
      for (;;) {
        c = t.get();
        if (c == -1) goto E;
        if (c == '-') {
          c = t.get();
          if (isdigit(c)) {
            y = 1;
            break;
          };
        } else if (isdigit(c))
          break;
        ;
      };
    for (;;) {
      if (c == -1) goto E;
      if (isdigit(c))
        r = r * 10 + (c ^ 48);
      else
        break;
      c = t.get();
    }
    t.unget(c);
  E:;
    if (y) r = -r;
  }
};
template <>
struct Q<char> {
  inline void operator()(MI &t, char &r) {
    int c;
    for (;;) {
      c = t.get();
      if (c == -1) {
        r = -1;
        return;
      };
      if (!isspace(c)) {
        r = c;
        return;
      };
    }
  }
};
template <typename T>
inline MI &MI::operator>(T &t) {
  Q<T>()(*this, t);
  return *this;
}
template <typename T>
std::ostream &operator<(std::ostream &out, const T &t) {
  return out << t;
}
using std::cout;
MI cin;
using std::make_pair;
using std::map;
using std::pair;
using std::vector;
const int nmax = 200001;
const int mmax = 200001;
const int tmax = 524289;
int n, m, q;
struct edge {
  int x, y, w;
  edge() {}
  edge(int x, int y) : x(x), y(y) {}
  edge(int x, int y, int w) : x(x), y(y), w(w) {}
  inline bool operator<(const edge &t) const {
    return (x == t.x) ? (y < t.y) : (x < t.x);
  }
} es[mmax * 2];
int tot;
map<edge, int> lst;
vector<pair<int, int> > sta;
int f[nmax], dis[nmax], wei[nmax];
pair<int, int> qs[mmax];
inline int getf(int x) {
  while (x != f[x]) x = f[x];
  return x;
}
inline int calc(int x) {
  int ret = 0;
  while (x != f[x]) {
    ret ^= wei[x];
    x = f[x];
  }
  return ret;
}
inline bool merge(int x, int y, int w) {
  if (x == y) return false;
  if (dis[x] > dis[y]) std::swap(x, y);
  sta.push_back(make_pair(x, dis[y]));
  wei[x] = w;
  f[x] = y;
  if (dis[x] == dis[y]) ++dis[y];
  return true;
}
inline void undo() {
  const auto pa = sta.back();
  sta.pop_back();
  const int x = pa.first, y = f[x];
  wei[x] = 0;
  f[x] = x;
  dis[y] = pa.second;
}
struct linear_base {
  int a[30];
  linear_base() { memset(a, 0, sizeof(a)); }
  inline void insert(int x) {
    for (int i = 29; ~i; --i) {
      if (!(x & (1 << i))) continue;
      if (a[i])
        x ^= a[i];
      else {
        a[i] = x;
        break;
      }
    }
  }
  inline int query(int x) {
    for (int i = 29; ~i; --i)
      if ((x ^ a[i]) < x) x ^= a[i];
    return x;
  }
};
namespace seg {
vector<int> as[nmax * 4];
int ll, rr, vv;
void _update(int x, int l, int r) {
  if (ll <= l && r <= rr) return as[x].push_back(vv);
  const int mid = (l + r) >> 1;
  if (ll <= mid) _update((x << 1), l, mid);
  if (mid < rr) _update(((x << 1) | 1), mid + 1, r);
}
inline void update(int l, int r, int v) {
  ll = l;
  rr = r;
  vv = v;
  _update(1, 1, q);
}
void solve(int x = 1, int l = 1, int r = q, linear_base base = linear_base()) {
  int cnt = 0;
  for (int d : as[x]) {
    const edge &e = es[d];
    const int fx = getf(e.x), fy = getf(e.y);
    const int w = calc(e.x) ^ calc(e.y) ^ e.w;
    if (fx == fy)
      base.insert(w);
    else
      cnt += merge(fx, fy, w);
  }
  if (l == r) {
    if (qs[l].first)
      cout < base.query(calc(qs[l].first) ^ calc(qs[l].second)) < ('\n');
  } else {
    const int mid = (l + r) >> 1;
    solve((x << 1), l, mid, base);
    solve(((x << 1) | 1), mid + 1, r, base);
  }
  while (cnt--) undo();
}
}  // namespace seg
int main() {
  cin > n > m;
  for (int i = 1; i <= m; ++i) {
    int x = (cin.read<int>()), y = (cin.read<int>());
    if (x > y) std::swap(x, y);
    lst[edge(x, y, (cin.read<int>()))] = 1;
  }
  cin > q;
  for (int i = 1; i <= q; ++i) {
    int op = (cin.read<int>()), x = (cin.read<int>()), y = (cin.read<int>());
    if (x > y) std::swap(x, y);
    switch (op) {
      case 1: {
        lst[edge(x, y, (cin.read<int>()))] = i;
        break;
      }
      case 2: {
        auto iter = lst.find(edge(x, y));
        assert(iter != lst.end());
        es[++tot] = iter->first;
        seg::update(iter->second, i, tot);
        lst.erase(iter);
        break;
      }
      case 3: {
        qs[i] = make_pair(x, y);
        break;
      }
      default:
        assert(false);
    }
  }
  for (auto pa : lst) {
    es[++tot] = pa.first;
    seg::update(pa.second, q, tot);
  }
  for (int i = 1; i <= n; ++i) f[i] = i;
  seg::solve();
  return 0;
}