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 = 1e9 + 7;
int add(int a, int b) {
  if ((a += b) >= P) a -= P;
  return a < 0 ? a + P : a;
}
int mul(int a, int b) { return 1ll * a * b % P; }
int kpow(int a, int b) {
  int r = 1;
  for (; b; b >>= 1, a = mul(a, a)) {
    if (b & 1) r = mul(r, a);
  }
  return r;
}
const int N = 1e3 + 5;
const long long mod = 998244353;
int na, nb;
long long mx, l1[N], r1[N], l2[N], r2[N];
set<pair<long long, long long> > st;
vector<pair<long long, long long> > p[N];
void ins(long long L, long long R, long long l, long long r, int d) {
  p[d].push_back(pair<long long, long long>(l, r));
  if (L <= l && r <= R) return;
  long long m = l + r >> 1;
  if (L <= m) ins(L, R, l, m, d + 1);
  if (R > m) ins(L, R, m + 1, r, d + 1);
}
void cal(long long L, long long R, long long l, long long r, int d) {
  if (L <= l && r <= R) {
    for (auto it : p[d]) {
      long long tmp = it.first ^ l;
      st.insert(pair<long long, long long>(tmp, tmp + r - l));
    }
    return;
  }
  long long m = l + r >> 1;
  if (L <= m) cal(L, R, l, m, d + 1);
  if (R > m) cal(L, R, m + 1, r, d + 1);
}
void solve() {
  for (int i = (0); i < (100); i++) p[i].clear();
  for (int i = (1); i < (na + 1); i++) ins(l1[i], r1[i], 0, mx, 0);
  for (int i = (1); i < (nb + 1); i++) cal(l2[i], r2[i], 0, mx, 0);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  mx = (1ll << 61) - 1;
  cin >> na;
  for (int i = (1); i < (na + 1); i++) cin >> l1[i] >> r1[i];
  cin >> nb;
  for (int i = (1); i < (nb + 1); i++) cin >> l2[i] >> r2[i];
  solve();
  swap(na, nb);
  swap(l1, l2);
  swap(r1, r2);
  solve();
  long long ans = 0, pr = 0, inv = (mod + 1) / 2;
  for (auto it : st) {
    if (it.second < pr) continue;
    long long tl = max(it.first, pr);
    ans = (ans + (tl % mod + it.second % mod) % mod *
                     ((it.second - tl + 1) % mod) % mod * inv % mod) %
          mod;
    pr = max(pr, it.second + 1);
  }
  cout << ans << "\n";
  return 0;
}
