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 P = 998244353;
const int N = 111;
inline long long qpow(long long a, long long b) {
  long long ans = 1;
  for (; b; b >>= 1, a = a * a % P)
    if (b & 1) ans = ans * a % P;
  return ans;
}
inline int Add(int a, int b) {
  a += b;
  if (a >= P) a -= P;
  return a;
}
inline int Dec(int a, int b) {
  a -= b;
  if (a < 0) a += P;
  return a;
}
inline int mul(int a, int b) { return (long long)a * b % P; }
int T = 0;
const int M = 1000003;
struct hash_ {
  struct E {
    long long v;
    int w;
    E* nxt;
  } * g[M + 1], pool[1000003], *cur = pool, *p;
  int vis[M + 1];
  void add(long long v, int w) {
    int u = v % M;
    if (vis[u] < T) vis[u] = T, g[u] = NULL;
    for (p = g[u]; p; p = p->nxt)
      if (p->v == v) {
        p->w += w;
        return;
      }
    p = cur++;
    p->v = v;
    p->w = w;
    p->nxt = g[u];
    g[u] = p;
  }
  void init() { T++, cur = pool; }
} hs;
int cnt = 0;
pair<long long, int> TT[10010];
void dfs(int p, long long l, long long r, long long L, long long R) {
  if (l == L && r == R) {
    TT[++cnt] = pair<long long, int>(L, p);
    return;
  }
  long long mid = (l + r) >> 1;
  if (R <= mid)
    dfs(p - 1, l, mid, L, R);
  else if (L > mid)
    dfs(p - 1, mid + 1, r, L, R);
  else {
    dfs(p - 1, l, mid, L, mid);
    dfs(p - 1, mid + 1, r, mid + 1, R);
  }
}
int na, nb;
pair<long long, long long> a[N], b[N];
vector<pair<long long, int> > A[N], B[N], rr;
int main() {
  auto mer = [&](pair<long long, long long> a[], int& n) {
    sort(a + 1, a + 1 + n);
    int cc = 1;
    for (int i = (2); i <= (n); ++i) {
      if (a[cc].second >= a[i].first)
        a[cc].second = max(a[cc].second, a[i].second);
      else
        a[++cc] = a[i];
    }
    n = cc;
  };
  cin >> na;
  for (int i = (1); i <= (na); ++i) cin >> a[i].first >> a[i].second;
  mer(a, na);
  cin >> nb;
  for (int i = (1); i <= (nb); ++i) cin >> b[i].first >> b[i].second;
  mer(b, nb);
  for (int i = (1); i <= (na); ++i) {
    cnt = 0;
    dfs(60, 0, (1ll << 60) - 1, a[i].first, a[i].second);
    A[i].resize(cnt);
    for (int j = (1); j <= (cnt); ++j) A[i][j - 1] = TT[j];
  }
  for (int i = (1); i <= (nb); ++i) {
    cnt = 0;
    dfs(60, 0, (1ll << 60) - 1, b[i].first, b[i].second);
    B[i].resize(cnt);
    for (int j = (1); j <= (cnt); ++j) B[i][j - 1] = TT[j];
  }
  for (int i = (1); i <= (na); ++i)
    for (int j = (1); j <= (nb); ++j) {
      hs.init();
      for (int i1 = (0); i1 <= (A[i].size() - 1); ++i1)
        for (int j1 = (0); j1 <= (B[j].size() - 1); ++j1) {
          pair<long long, int> la = A[i][i1], lb = B[j][j1];
          int tmp = max(la.second, lb.second);
          long long tl = ((la.first ^ lb.first) >> tmp) << tmp;
          hs.add(tl, 1);
          hs.add(tl + (1ll << tmp), -1);
        }
      for (hs.p = hs.pool; hs.p != hs.cur; hs.p++) {
        rr.push_back({hs.p->v, hs.p->w});
      }
    }
  long long inv2 = (P + 1) / 2;
  auto cals = [&](long long l, long long r) {
    l %= P, r %= P;
    return ((l + r) * (r - l + 1 + P) % P) * inv2 % P;
  };
  sort(rr.begin(), rr.end());
  long long pre = 0;
  int ss = 0, ans = 0;
  for (int i = (0); i <= (rr.size() - 1); ++i) {
    if (ss > 0) {
      ans = Add(ans, cals(pre, rr[i].first - 1));
    }
    ss += rr[i].second;
    pre = rr[i].first;
  }
  cout << ans << '\n';
}
