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 long long INF = (1LL << 60) - 1;
const long long mo = 998244353;
const long long inv2 = 499122177;
template <typename _T>
void read(_T &x) {
  _T f = 1;
  x = 0;
  char s = getchar();
  while ('0' > s || '9' < s) {
    if (s == '-') f = -1;
    s = getchar();
  }
  while ('0' <= s && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = getchar();
  }
  x *= f;
}
struct ming {
  long long l, r;
} a[105], b[105];
int na, nb, tot, ch[100000][2], root;
vector<ming> tpa[65], tpb[65], ans;
void work1(int &rt, long long l, long long r, long long al, long long ar,
           int id) {
  if (!rt)
    rt = ++tot, ch[rt][0] = ch[rt][1] = 0, tpa[id].push_back((ming){l, r});
  if (al <= l && r <= ar) return;
  long long mid = l + r >> 1;
  if (al <= mid) work1(ch[rt][0], l, mid, al, ar, id + 1);
  if (ar > mid) work1(ch[rt][1], mid + 1LL, r, al, ar, id + 1);
}
void work2(long long l, long long r, long long al, long long ar, int id) {
  if (al <= l && r <= ar) {
    tpb[id].push_back((ming){l, r});
    return;
  }
  long long mid = l + r >> 1;
  if (al <= mid) work2(l, mid, al, ar, id + 1);
  if (ar > mid) work2(mid + 1LL, r, al, ar, id + 1);
}
void solve() {
  tot = root = 0;
  for (int i = 0; i <= 60; i++) tpa[i].clear(), tpb[i].clear();
  for (int i = 1; i <= na; i++) work1(root, 0, INF, a[i].l, a[i].r, 0);
  for (int i = 1; i <= nb; i++) work2(0, INF, b[i].l, b[i].r, 0);
  for (int i = 1; i <= 60; i++) {
    int siz1 = tpa[i].size(), siz2 = tpb[i].size();
    for (int j = 0; j < siz1; j++)
      for (int k = 0; k < siz2; k++) {
        ming u = tpa[i][j], v = tpb[i][k];
        long long tmp = v.l ^ v.r, num = u.l ^ v.l;
        ans.push_back((ming){num & (~tmp), num | tmp});
      }
  }
}
int cmp(ming x, ming y) { return x.l < y.l; }
signed main() {
  read(na);
  for (int i = 1; i <= na; i++) read(a[i].l), read(a[i].r);
  read(nb);
  for (int i = 1; i <= nb; i++) read(b[i].l), read(b[i].r);
  solve();
  swap(a, b);
  swap(na, nb);
  solve();
  int siz = ans.size();
  sort(ans.begin(), ans.end(), cmp);
  long long tl = 0, tr = 0, answer = 0;
  for (int i = 0; i < siz; i++) {
    ming t = ans[i];
    if (t.l <= tr + 1)
      tr = max(tr, t.r);
    else
      answer =
          (answer + (tr + tl) % mo * ((tr - tl + 1) % mo) % mo * inv2 % mo) %
          mo,
      tl = t.l, tr = t.r;
  }
  answer =
      (answer + (tr + tl) % mo * ((tr - tl + 1) % mo) % mo * inv2 % mo) % mo;
  printf("%lld\n", answer);
  return 0;
}
