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>
const long long maxn = 62;
std::vector<std::pair<long long, long long> > Vec, AP[maxn + 1], AQ[maxn],
    BP[maxn], BQ[maxn];
long long read() {
  char c = getchar();
  long long ans = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return ans;
}
void Write(long long x) {
  if (x < 10)
    putchar(x + '0');
  else
    Write(x / 10), putchar(x % 10 + '0');
  return;
}
long long calc(long long l, long long r) {
  if ((r - l) & 1)
    return (r - l + 1) / 2 % 998244353 * ((l + r) % 998244353) % 998244353;
  return (l + r) / 2 % 998244353 * ((r - l + 1) % 998244353) % 998244353;
}
long long max(long long x, long long y) { return x > y ? x : y; }
long long min(long long x, long long y) { return x < y ? x : y; }
long long get_ans() {
  if (Vec.empty()) return 0;
  std::sort(Vec.begin(), Vec.end());
  Vec.resize(std::unique(Vec.begin(), Vec.end()) - Vec.begin());
  long long ans = 0, curl = Vec[0].first, curr = Vec[0].second;
  for (long long i = 1; i < Vec.size(); i++)
    if (Vec[i].first > curr)
      ans += calc(curl, curr), curl = Vec[i].first, curr = Vec[i].second;
    else
      curr = max(curr, Vec[i].second);
  return ans + calc(curl, curr);
}
std::pair<long long, long long> make(long long x, long long w) {
  return std::make_pair(x, x + (1ll << w) - 1);
}
void InsertA(long long L, long long R, long long l, long long r, long long w) {
  if (l <= L && R <= r)
    AP[w].push_back(std::make_pair(L, R)),
        AQ[w].push_back(std::make_pair(L, R));
  else {
    long long mid = (L + R) / 2;
    if (mid >= l) InsertA(L, mid, l, r, w - 1);
    if (mid < r) InsertA(mid + 1, R, l, r, w - 1);
    AQ[w].push_back(std::make_pair(L, R));
  }
  return;
}
void InsertB(long long L, long long R, long long l, long long r, long long w) {
  if (l <= L && R <= r)
    BP[w].push_back(std::make_pair(L, R)),
        BQ[w].push_back(std::make_pair(L, R));
  else {
    long long mid = (L + R) / 2;
    if (mid >= l) InsertB(L, mid, l, r, w - 1);
    if (mid < r) InsertB(mid + 1, R, l, r, w - 1);
    BQ[w].push_back(std::make_pair(L, R));
  }
  return;
}
int main() {
  long long n = read();
  for (long long i = 1, x, y; i <= n; i++)
    x = read(), y = read(), InsertA(0, (1ll << maxn) - 1, x, y, maxn);
  long long m = read();
  for (long long i = 1, x, y; i <= m; i++)
    x = read(), y = read(), InsertB(0, (1ll << maxn) - 1, x, y, maxn);
  for (long long i = 0; i < maxn; i++) {
    for (auto j : AP[i])
      for (auto k : BQ[i])
        Vec.push_back(make(j.first ^ (k.first & (-1ll << i)), i));
    for (auto j : AQ[i])
      for (auto k : BP[i])
        Vec.push_back(make(k.first ^ (j.first & (-1ll << i)), i));
  }
  return Write(get_ans() % 998244353), 0;
}
