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 maxN = 1e7 + 10, mod = 998244353, I = (mod + 1) >> 1;
const long long lim = (1ll << 60) - 1;
int na, nb, cnt, ans;
int ch[maxN + 1][2];
int ra[105], rb[105];
inline int build(long long l, long long r, long long x, long long y) {
  if (x <= l && r <= y) return -1;
  int node = ++cnt;
  long long mid = (l + r) >> 1;
  if (x <= mid) ch[node][0] = build(l, mid, x, y);
  if (y > mid) ch[node][1] = build(mid + 1, r, x, y);
  return node;
}
inline int merge(int u, int v) {
  if (!u || !v) return u | v;
  if (u == -1 || v == -1) return -1;
  int L = merge(ch[u][0], ch[v][0]);
  int R = merge(ch[u][1], ch[v][1]);
  if (L == -1 && R == -1) return -1;
  int node = ++cnt;
  ch[node][0] = L, ch[node][1] = R;
  return node;
}
inline int XOR(int u, int v) {
  if (!u || !v) return 0;
  if (u == -1 || v == -1) return -1;
  int L = merge(XOR(ch[u][0], ch[v][0]), XOR(ch[u][1], ch[v][1]));
  int R = merge(XOR(ch[u][0], ch[v][1]), XOR(ch[u][1], ch[v][0]));
  if (L == -1 && R == -1) return -1;
  int node = ++cnt;
  ch[node][0] = L, ch[node][1] = R;
  return node;
}
inline void calc(int node, long long l, long long r) {
  if (!node) return;
  if (node == -1) {
    int x = l % mod, y = r % mod;
    int t = 1ll * (x + y) * (y + mod - x + 1) % mod * I % mod;
    ans = (ans + t) % mod;
    return;
  }
  long long mid = (l + r) >> 1;
  calc(ch[node][0], l, mid);
  calc(ch[node][1], mid + 1, r);
}
int main() {
  scanf("%d", &na);
  for (int i = 1; i <= na; i++) {
    long long l, r;
    scanf("%lld %lld", &l, &r);
    ra[i] = build(0, lim, l, r);
  }
  scanf("%d", &nb);
  for (int i = 1; i <= nb; i++) {
    long long l, r;
    scanf("%lld %lld", &l, &r);
    rb[i] = build(0, lim, l, r);
  }
  int rt = 0;
  for (int i = 1; i <= na; i++)
    for (int j = 1; j <= nb; j++) rt = merge(rt, XOR(ra[i], rb[j]));
  calc(rt, 0, lim);
  printf("%d\n", ans);
  return 0;
}
