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>
using namespace std;
inline long long gi() {
  char c;
  long long num = 0, flg = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flg = -1;
  while (c >= '0' && c <= '9') {
    num = num * 10 + 1ll * c - 48;
    c = getchar();
  }
  return num * flg;
}
const int mod = 998244353;
const int inv2 = 499122177;
struct SegTrie {
  int ch[1000005][2], tot, rt;
  bool flg[1000005];
  void insert(int &i, long long l, long long r, long long ql, long long qr) {
    if (!i) i = ++tot;
    if (ql == l && r == qr) {
      flg[i] = 1;
      return;
    }
    long long mid = (l + r) >> 1;
    if (ql < mid) insert(ch[i][0], l, mid, ql, qr < mid ? qr : mid);
    if (qr > mid) insert(ch[i][1], mid, r, ql > mid ? ql : mid, qr);
  }
} A, B;
vector<pair<int, int> > q[60 + 5];
long long BFS(int d, long long sum) {
  for (int i = 0; i < (int)q[d].size(); i++)
    if (A.flg[q[d][i].first] || B.flg[q[d][i].second])
      return (sum + 1ll * ((1ll << d) - 1) % mod * inv2) % mod *
             ((1ll << d) % mod) % mod;
  long long ret = 0;
  for (int x = 0; x <= 1; x++) {
    q[d - 1].clear();
    for (int i = 0; i < (int)q[d].size(); i++)
      for (int y = 0; y <= 1; y++)
        if (A.ch[q[d][i].first][y] && B.ch[q[d][i].second][x ^ y])
          q[d - 1].push_back(
              make_pair(A.ch[q[d][i].first][y], B.ch[q[d][i].second][x ^ y]));
    if (q[d - 1].size())
      ret = (ret + 1ll * BFS(d - 1, sum | (1ll * x << (d - 1)))) % mod;
  }
  return ret;
}
int main() {
  int na, nb, i;
  long long l, r;
  na = gi();
  for (i = 1; i <= na; i++) {
    l = gi();
    r = gi() + 1;
    A.insert(A.rt, 0, 1ll << 60, l, r);
  }
  nb = gi();
  for (i = 1; i <= nb; i++) {
    l = gi();
    r = gi() + 1;
    B.insert(B.rt, 0, 1ll << 60, l, r);
  }
  q[60].push_back(make_pair(A.rt, B.rt));
  printf("%lld\n", BFS(60, 0ll));
}
