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 Mod = 998244353;
const int inv2 = 499122177;
const int M = 61;
vector<pair<long long, int> > vec;
vector<long long> x[2][62], y[2][62];
void work(long long l, long long r, long long L, long long R, int d, int o) {
  if (L <= l && r <= R) {
    x[o][d].push_back(l);
    return;
  }
  y[o][d].push_back(l);
  long long mid = (l + r) >> 1;
  if (L <= mid) work(l, mid, L, R, d - 1, o);
  if (R > mid) work(mid + 1, r, L, R, d - 1, o);
  return;
}
int Sum(long long n) {
  n %= Mod;
  return n * (n + 1) % Mod * inv2 % Mod;
}
int Sum(long long l, long long r) {
  return ((r - l) % Mod) * ((r + l - 1) % Mod) % Mod * inv2 % Mod;
}
void Ins(long long l, long long r) {
  vec.push_back(make_pair(l, 1));
  vec.push_back(make_pair(r, -1));
  return;
}
int main() {
  int n, m;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    long long l, r;
    scanf("%lld %lld", &l, &r);
    work(0, (1ll << M) - 1, l, r, M, 0);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    long long l, r;
    scanf("%lld %lld", &l, &r);
    work(0, (1ll << M) - 1, l, r, M, 1);
  }
  for (int i = 0; i <= M; i++) {
    for (int j = 0; j < x[0][i].size(); j++) {
      long long a = x[0][i][j];
      for (int k = 0; k < x[1][i].size(); k++) {
        long long b = x[1][i][k];
        Ins(a ^ b, (a ^ b) + (1ll << i));
      }
      for (int k = 0; k < y[1][i].size(); k++) {
        long long b = y[1][i][k];
        Ins(a ^ b, (a ^ b) + (1ll << i));
      }
    }
    for (int j = 0; j < x[1][i].size(); j++) {
      long long a = x[1][i][j];
      for (int k = 0; k < y[0][i].size(); k++) {
        long long b = y[0][i][k];
        Ins(a ^ b, (a ^ b) + (1ll << i));
      }
    }
  }
  sort(vec.begin(), vec.end());
  int ans = 0;
  long long l = 0, r = 0;
  int cnt = 0;
  long long last = 0;
  for (int i = 0; i < vec.size(); i++) {
    if (cnt > 0) {
      ans = (ans + Sum(last, vec[i].first)) % Mod;
    }
    cnt += vec[i].second;
    last = vec[i].first;
  }
  printf("%d\n", ans);
  return 0;
}
