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;
const int N = 105, mo = 998244353;
struct range {
  long long l, d;
  bool tp;
  inline void go(long long x) {
    if (d > x) d -= x, tp == 0 ? l += x : l -= x;
  }
} A[N], B[N], C[N], D[N];
pair<long long, int> a[6000000];
int xb;
int na, nb, i, j, x, ans;
long long la[N], ra[N], lb[N], rb[N], ma[N], mb[N];
inline void in(int& n, range* a, range* b) {
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    long long l, r, m;
    scanf("%lld%lld", &l, &r);
    for (m = l; m + (m & -m) <= r; m += m & -m)
      ;
    a[i] = (range){m - 1, m - l, 1};
    b[i] = (range){m, r - m + 1, 0};
  }
}
inline void add(long long l, long long d) {
  a[++xb] = {l, 1};
  a[++xb] = {l + d, -1};
}
inline void work(range a, range b) {
  long long x = 1ll << 60;
  for (; x; x >>= 1) {
    bool fa = a.d > x, fb = b.d > x;
    if (!fa && !fb) continue;
    if (fa && fb) return add((a.l ^ b.l) & ~(x * 2 - 1), x * 2);
    if (fa ^ fb) add((a.l ^ b.l) & ~(x - 1), x);
    a.go(x);
    b.go(x);
  }
  add(a.l ^ b.l, 1);
}
int main() {
  in(na, A, B);
  in(nb, C, D);
  for (i = 0; i < na; ++i)
    for (j = 0; j < nb; ++j) {
      if (A[i].d && C[j].d) work(A[i], C[j]);
      if (A[i].d && D[j].d) work(A[i], D[j]);
      if (B[i].d && C[j].d) work(B[i], C[j]);
      if (B[i].d && D[j].d) work(B[i], D[j]);
    }
  sort(a + 1, a + xb + 1);
  for (i = 1; i <= xb; i = j) {
    for (j = i; j <= xb && a[j].first == a[i].first; x += a[j++].second)
      ;
    if (x)
      ans = (ans + (a[i].first + a[j].first - 1) % mo *
                       ((a[j].first - a[i].first) % mo)) %
            mo;
  }
  ans& 1 ? ans += mo : 0;
  ans >>= 1;
  printf("%d\n", ans);
  return 0;
}
