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 mxn = 100010, md = 998244353, inv2 = 499122177;
const long long N = (1ll << 60) - 1;
struct nd {
  long long l, r;
  bool operator<(const nd x) const { return l < x.l || (l == x.l && r > x.r); }
  nd operator+(const nd y) const { return (nd){l ^ y.l, l ^ y.r}; }
};
void ins(long long l, long long r, long long x, long long y, nd *a, int &n) {
  if (r < x || l > y) return;
  if (l >= x && r <= y) return (void)(a[++n] = (nd){l, r});
  ins(l, ((l + r) >> 1), x, y, a, n), ins(((l + r) >> 1) + 1, r, x, y, a, n);
}
void upd(nd *a, int &n) {
  sort(a + 1, a + n + 1);
  int cur = 0;
  a[0].r = -1;
  for (int i = 1; i <= n; ++i)
    if (a[i].l > a[cur].r) a[++cur] = a[i];
  n = cur;
}
nd A[mxn], B[mxn], a[mxn], b[mxn], c[5000010];
int n, m, sa, sb, sc;
int main() {
  scanf("%d", &sa);
  for (int i = 1; i <= sa; ++i) {
    long long x, y;
    scanf("%I64d%I64d", &x, &y);
    ins(0, N, x, y, A, n);
  }
  upd(A, n);
  scanf("%d", &sa);
  for (int i = 1; i <= sa; ++i) {
    long long x, y;
    scanf("%I64d%I64d", &x, &y);
    ins(0, N, x, y, B, m);
  }
  upd(B, m);
  for (long long len = 1; len < N; len <<= 1) {
    sa = sb = 0;
    for (int i = 1; i <= n; ++i)
      if (A[i].r - A[i].l + 1 == len) a[++sa] = A[i];
    for (int i = 1; i <= m; ++i) {
      long long l = B[i].l, r = B[i].r;
      if (r - l + 1 > len) continue;
      for (; r - l + 1 < len;)
        if (((r + 1) / (r - l + 1)) & 1)
          r += r - l + 1;
        else
          l -= r - l + 1;
      b[++sb] = (nd){l, r};
    }
    upd(a, sa), upd(b, sb);
    for (int i = 1; i <= sa; ++i)
      for (int j = 1; j <= sb; ++j) c[++sc] = a[i] + b[j];
  }
  upd(c, sc);
  for (long long len = 1; len < N; len <<= 1) {
    sa = sb = 0;
    for (int i = 1; i <= m; ++i)
      if (B[i].r - B[i].l + 1 == len) a[++sa] = B[i];
    for (int i = 1; i <= n; ++i) {
      long long l = A[i].l, r = A[i].r;
      if (r - l + 1 > len) continue;
      for (; r - l + 1 < len;)
        if (((r + 1) / (r - l + 1)) & 1)
          r += r - l + 1;
        else
          l -= r - l + 1;
      b[++sb] = (nd){l, r};
    }
    upd(a, sa), upd(b, sb);
    for (int i = 1; i <= sa; ++i)
      for (int j = 1; j <= sb; ++j) c[++sc] = a[i] + b[j];
  }
  upd(c, sc);
  int ans = 0;
  for (int i = 1; i <= sc; ++i)
    ans = (ans +
           (c[i].l + c[i].r) % md * ((c[i].r - c[i].l + 1) % md) % md * inv2) %
          md;
  printf("%d\n", ans);
}
