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;
inline long long read() {
  long long x = 0;
  bool f = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) f = (ch == '-');
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
  return f ? -x : x;
}
const long long inf = 1ll << 60;
const long long mod = 998244353;
const long long inv2 = (mod + 1) / 2;
inline long long calc(long long l, long long r) {
  l %= mod;
  r %= mod;
  return (l + r) * (r - l + 1 + mod) % mod * inv2 % mod;
}
long long na, nb, ans;
struct node {
  long long w, a;
  node(long long x, long long y) {
    w = x;
    a = y;
  }
  inline bool friend operator<(node a, node b) {
    return a.w == b.w ? a.a < b.a : a.w < b.w;
  }
  inline bool friend operator!=(node a, node b) {
    return a.w != b.w || a.a != b.a;
  }
};
map<long long, long long> mp;
vector<node> a[70], b[70], A[70], B[70], c;
void solve(vector<node>* a, vector<node>* b) {
  for (int i = 0; i <= 60; ++i) {
    sort(a[i].begin(), a[i].end());
    sort(b[i].begin(), b[i].end());
    if (!a[i].size() || !b[i].size()) continue;
    for (int j = 0; j < a[i].size(); ++j)
      if (!j || a[i][j] != a[i][j - 1])
        for (int k = 0; k < b[i].size(); ++k)
          if (!k || b[i][k] != b[i][k - 1]) {
            long long x = a[i][j].a ^ b[i][k].a;
            c.push_back(node(x << i, ((x + 1) << i) - 1));
          }
  }
}
void cover(long long l, long long r, long long ql, long long qr,
           vector<node>* a, vector<node>* A) {
  int w = mp[r - l + 1];
  A[w].push_back(node(w, l >> w));
  if (ql <= l && r <= qr) return a[w].push_back(node(w, l >> w));
  long long mid = (l + r) >> 1;
  if (ql <= mid) cover(l, mid, ql, qr, a, A);
  if (qr > mid) cover(mid + 1, r, ql, qr, a, A);
}
int main() {
  for (int i = 0; i <= 60; ++i) mp[1ll << i] = i;
  na = read();
  for (int i = 1; i <= na; ++i) {
    long long l = read(), r = read();
    cover(0, inf - 1, l, r, a, A);
  }
  nb = read();
  for (int i = 1; i <= nb; ++i) {
    long long l = read(), r = read();
    cover(0, inf - 1, l, r, b, B);
  }
  solve(a, B);
  solve(b, A);
  sort(c.begin(), c.end());
  for (int i = 0; i < c.size(); ++i)
    ;
  long long L = c[0].w, R = c[0].a;
  for (int i = 1; i < c.size(); ++i) {
    long long l = c[i].w, r = c[i].a;
    if (l <= R)
      R = max(R, r);
    else
      ans += calc(L, R), L = l, R = r;
  }
  ans += calc(L, R);
  printf("%lld\n", ans % mod);
  return 0;
}
