You are given two sets of integers: A and B. You need to output the sum of elements in the set C = \\{x | x = a ⊕ b, a ∈ A, b ∈ B\} modulo 998244353, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Each number should be counted only once.

For example, if A = \{2, 3\} and B = \{2, 3\} you should count integer 1 only once, despite the fact that you can get it as 3 ⊕ 2 and as 2 ⊕ 3. So the answer for this case is equal to 1 + 0 = 1.

Let's call a segment [l; r] a set of integers \\{l, l+1, ..., r\}.

The set A is given as a union of n_A segments, the set B is given as a union of n_B segments.

Input

The first line contains a single integer n_A (1 ≤ n_A ≤ 100).

The i-th of the next n_A lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}), describing a segment of values of set A.

The next line contains a single integer n_B (1 ≤ n_B ≤ 100).

The i-th of the next n_B lines contains two integers l_j and r_j (1 ≤ l_j ≤ r_j ≤ 10^{18}), describing a segment of values of set B.

Note that segments in both sets may intersect.

Output

Print one integer — the sum of all elements in set C = \\{x | x = a ⊕ b, a ∈ A, b ∈ B\} modulo 998244353.

Examples

Input


2
3 5
5 8
3
1 2
1 9
2 9


Output


112


Input


1
1 9
2
2 4
2 10


Output


120

Note

In the second example, we can discover that the set C = \{0,1,...,15\}, which means that all numbers between 0 and 15 can be represented as a ⊕ b.
#include <bits/stdc++.h>
inline int read() {
  char c = getchar();
  int x = 0, ft = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') ft = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  return x * ft;
}
const int N = 105, M = 5e4 + 5, L = 4e6 + 5;
const int mod = 998244353, inv2 = (mod + 1) / 2;
int na, nb, n, ans;
long long l, r, m = (1ll << 60) - 1;
struct Segment_Tree {
  int rt, node_cnt, ch[M][2], dep[M], tag[M];
  long long num[M];
  void modify(long long ql, long long qr, int d, long long v, long long l,
              long long r, int& u) {
    if (!u) u = ++node_cnt, dep[u] = d, num[u] = v;
    if (ql <= l && r <= qr)
      tag[u] = 1;
    else {
      long long mid = (l + r) >> 1;
      if (ql <= mid) modify(ql, qr, d - 1, v, l, mid, ch[u][0]);
      if (qr > mid)
        modify(ql, qr, d - 1, v | (1ll << (d - 1)), mid + 1, r, ch[u][1]);
    }
  }
} a, b;
struct Elem {
  int dep;
  long long num;
} q[L];
inline bool operator<(Elem a, Elem b) {
  return a.num == b.num ? a.dep > b.dep : a.num < b.num;
}
int main() {
  na = read();
  while (na--) scanf("%lld%lld", &l, &r), a.modify(l, r, 60, 0, 0, m, a.rt);
  nb = read();
  while (nb--) scanf("%lld%lld", &l, &r), b.modify(l, r, 60, 0, 0, m, b.rt);
  for (int i = 1; i <= a.node_cnt; ++i)
    for (int j = 1; j <= b.node_cnt; ++j) {
      if (a.dep[i] == b.dep[j] && (a.tag[i] || b.tag[j])) {
        q[++n] = (Elem){a.dep[i], a.num[i] ^ b.num[j]};
      }
    }
  std::sort(q + 1, q + 1 + n);
  int las_d = -1;
  long long las_m = -1;
  for (int i = 1; i <= n; ++i) {
    if (las_d != -1 && las_d >= q[i].dep &&
        (las_m >> las_d) == (q[i].num >> las_d))
      continue;
    las_d = q[i].dep;
    las_m = q[i].num;
    ans = (las_m % mod * ((1ll << las_d) % mod) + ans) % mod;
    ans = (((1ll << las_d) % mod) * (((1ll << las_d) - 1) % mod) % mod * inv2 +
           ans) %
          mod;
  }
  printf("%d\n", ans);
  return 0;
}
