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;
void read(long long &x) {
  x = 0;
  long long f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -f;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  x *= f;
}
void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (!x) return;
  print(x / 10), putchar(x % 10 + 48);
}
void write(long long x) {
  if (!x)
    putchar('0');
  else
    print(x);
  putchar('\n');
}
const long long maxn = 1e6 + 10;
const long long inf = 1e9;
const double eps = 1e-8;
const long long mod = 998244353;
const long long inv2 = 499122177;
long long n, m;
vector<pair<long long, long long> > t[62], s[62], ans, t2[62], s2[62];
void get(long long l, long long r, long long x, long long y, long long d,
         long long op) {
  if (op)
    s[d].push_back(make_pair(l, r));
  else
    t2[d].push_back(make_pair(l, r));
  if (x <= l && r <= y) {
    if (!op)
      t[d].push_back(make_pair(l, r));
    else
      s2[d].push_back(make_pair(l, r));
    return;
  }
  long long mid = (l + r) >> 1;
  if (x <= mid) get(l, mid, x, y, d + 1, op);
  if (y > mid) get(mid + 1, r, x, y, d + 1, op);
}
long long get_sum(long long l, long long r) {
  return (l + r) % mod * ((r - l + 1) % mod) % mod * inv2 % mod;
}
signed main() {
  read(n);
  for (long long i = 1, l, r; i <= n; i++)
    read(l), read(r), get(0, (1ll << 60) - 1, l, r, 1, 0);
  read(m);
  for (long long i = 1, l, r; i <= m; i++)
    read(l), read(r), get(0, (1ll << 60) - 1, l, r, 1, 1);
  for (long long i = 1; i <= 61; i++)
    for (auto x : t[i])
      for (auto y : s[i])
        ans.push_back(make_pair(x.first ^ y.first,
                                (x.first ^ y.first) + x.second - x.first));
  for (long long i = 1; i <= 61; i++)
    for (auto x : t2[i])
      for (auto y : s2[i])
        ans.push_back(make_pair(x.first ^ y.first,
                                (x.first ^ y.first) + x.second - x.first));
  sort(ans.begin(), ans.end());
  long long p = 0, res = 0;
  for (auto x : ans) {
    p = max(p, x.first - 1);
    if (x.second > p)
      res = (res + get_sum(p + 1, x.second)) % mod, p = x.second;
  }
  write(res);
  return 0;
}
