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;
const int M = 1e5 + 5;
const int mod = 998244353;
const int inv = 499122177;
inline long long read() {
  long long x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x;
}
long long lim = (1LL << 60) - 1;
int na, nb, rt, cnt;
int ch[M][2];
struct node {
  long long l, r;
  node() {}
  node(long long L, long long R) { l = L, r = R; }
} a[N], b[N];
vector<node> va[N], vb[N], ans;
int nd() {
  ch[++cnt][0] = 0, ch[cnt][1] = 0;
  return cnt;
}
void gnd1(int &o, long long l, long long r, long long x, long long y, int d) {
  if (!o) o = nd(), va[d].push_back(node(l, r));
  if (x <= l && r <= y) return;
  long long mid = (l + r) >> 1;
  if (x <= mid) gnd1(ch[o][0], l, mid, x, y, d + 1);
  if (mid < y) gnd1(ch[o][1], mid + 1, r, x, y, d + 1);
}
void gnd2(long long l, long long r, long long x, long long y, int d) {
  if (x <= l && r <= y) {
    vb[d].push_back(node(l, r));
    return;
  }
  long long mid = (l + r) >> 1;
  if (x <= mid) gnd2(l, mid, x, y, d + 1);
  if (mid < y) gnd2(mid + 1, r, x, y, d + 1);
}
void solve() {
  rt = cnt = 0;
  for (register int i = 0; i <= 60; i++) va[i].clear(), vb[i].clear();
  for (register int i = 1; i <= na; i++) gnd1(rt, 0, lim, a[i].l, a[i].r, 0);
  for (register int i = 1; i <= nb; i++) gnd2(0, lim, b[i].l, b[i].r, 0);
  for (register int i = 0; i <= 60; i++) {
    for (vector<node>::iterator it1 = va[i].begin(); it1 != va[i].end();
         it1++) {
      for (vector<node>::iterator it2 = vb[i].begin(); it2 != vb[i].end();
           it2++) {
        long long low = it2->l ^ it2->r;
        ans.push_back(
            node((it2->l ^ it1->l) & (~low), (it2->l ^ it1->l) | low));
      }
    }
  }
}
bool operator<(node a, node b) { return a.l < b.l; }
long long cal(long long l, long long r) {
  l %= mod, r %= mod;
  return (r - l + mod + 1) % mod * (l + r) % mod * inv % mod;
}
int main() {
  na = read();
  for (register int i = 1; i <= na; i++) a[i].l = read(), a[i].r = read();
  nb = read();
  for (register int i = 1; i <= nb; i++) b[i].l = read(), b[i].r = read();
  solve();
  swap(a, b), swap(na, nb), solve();
  sort(ans.begin(), ans.end());
  if (!ans.size()) return puts("0"), 0;
  long long L = ans.begin()->l, R = ans.begin()->r, anss = 0;
  for (vector<node>::iterator it = ans.begin() + 1; it != ans.end(); it++) {
    if (it->l <= R + 1)
      R = max(R, it->r);
    else
      (anss += cal(L, R)) %= mod, L = it->l, R = it->r;
  }
  anss = (anss + cal(L, R)) % mod;
  printf("%lld", anss);
}
