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 = 101;
const int BITS = 60;
struct node {
  int son[2];
  bool all;
  bool have;
} f[N * 200 * 4];
int na, nb;
int tot;
vector<pair<int, int> > d[BITS + 1];
void ins(long long l, int bits, int s, long long ll, long long rr) {
  if (l + (1ll << bits) - 1 < ll || rr < l) return;
  if (f[s].all) return;
  if (l >= ll && l + (1ll << bits) - 1 <= rr) {
    f[s].all = 1;
    f[s].have = 1;
    return;
  }
  f[s].have = 1;
  if (!f[s].son[0]) f[s].son[0] = ++tot;
  if (!f[s].son[1]) f[s].son[1] = ++tot;
  ins(l, bits - 1, f[s].son[0], ll, rr);
  ins(l + (1ll << (bits - 1)), bits - 1, f[s].son[1], ll, rr);
  f[s].all = (f[f[s].son[0]].all && f[f[s].son[1]].all);
}
const int mod = 998244353;
int add(int x, int y) {
  x += y;
  return x >= mod ? x - mod : x;
}
int sub(int x, int y) {
  x -= y;
  return x < 0 ? x + mod : x;
}
int mul(int x, int y) { return 1ll * x * y % mod; }
int calc(int x, int y) {
  int z = 1;
  while (y) {
    if (y & 1) z = mul(z, x);
    x = mul(x, x), y >>= 1;
  }
  return z;
}
int ni2 = calc(2, mod - 2);
int calc(long long x) { return mul(mul((x - 1) % mod, x % mod), ni2); }
int work(int prefix, int bits) {
  if (!d[bits].size()) return 0;
  for (auto u : d[bits]) {
    if (f[u.first].all || f[u.second].all) {
      return add(mul(prefix, (1ll << bits) % mod), calc(1ll << bits));
    }
  }
  int v = 0;
  for (int x = 0; x < 2; x++) {
    d[bits - 1].clear();
    for (int i = 0; i < 2; i++)
      for (auto u : d[bits])
        if (f[f[u.first].son[i]].have && f[f[u.second].son[i ^ x]].have)
          d[bits - 1].push_back({f[u.first].son[i], f[u.second].son[i ^ x]});
    v = add(work(add(prefix, (((long long)x) << (bits - 1)) % mod), bits - 1),
            v);
  }
  return v;
}
int main() {
  tot = 3;
  scanf("%d", &na);
  while (na--) {
    long long l, r;
    scanf("%lld %lld", &l, &r);
    ins(0, BITS, 1, l, r);
  }
  scanf("%d", &nb);
  while (nb--) {
    long long l, r;
    scanf("%lld %lld", &l, &r);
    ins(0, BITS, 2, l, r);
  }
  d[BITS].push_back({1, 2});
  printf("%d\n", work(0, BITS));
  return 0;
}
