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 Maxn = 100;
const long long Inf = (1ll << 60) - 1;
int n_a, n_b;
struct Segment {
  long long left, right;
} a[Maxn + 5], b[Maxn + 5];
vector<pair<long long, long long> > tmp_a[65], tmp_b[65];
vector<pair<long long, long long> > ans;
struct Segment_Node {
  int lson, rson;
} seg[Maxn * 1000 + 5];
int id_tot, Root;
int new_node() {
  id_tot++;
  seg[id_tot].lson = seg[id_tot].rson = 0;
  return id_tot;
}
void insert_a(long long l, long long r, int &root = Root, long long left = 0,
              long long right = Inf, int dep = 0) {
  if (l > right || r < left) {
    return;
  }
  if (root == 0) {
    root = new_node();
    tmp_a[dep].push_back(make_pair(left, right));
  }
  if (l <= left && r >= right) {
    return;
  }
  long long mid = (left + right) >> 1;
  insert_a(l, r, seg[root].lson, left, mid, dep + 1);
  insert_a(l, r, seg[root].rson, mid + 1, right, dep + 1);
}
void insert_b(long long l, long long r, long long left = 0,
              long long right = Inf, int dep = 0) {
  if (l > right || r < left) {
    return;
  }
  if (l <= left && r >= right) {
    tmp_b[dep].push_back(make_pair(left, right));
    return;
  }
  long long mid = (left + right) >> 1;
  insert_b(l, r, left, mid, dep + 1);
  insert_b(l, r, mid + 1, right, dep + 1);
}
void work() {
  id_tot = 0;
  Root = 0;
  for (int i = 0; i <= 60; i++) {
    tmp_a[i].clear();
    tmp_b[i].clear();
  }
  for (int i = 1; i <= n_a; i++) {
    insert_a(a[i].left, a[i].right);
  }
  for (int i = 1; i <= n_b; i++) {
    insert_b(b[i].left, b[i].right);
  }
  for (int i = 1; i <= 60; i++) {
    for (int j = 0; j < (int)tmp_a[i].size(); j++) {
      for (int k = 0; k < (int)tmp_b[i].size(); k++) {
        long long low = tmp_b[i][k].first ^ tmp_b[i][k].second;
        ans.push_back(
            make_pair((tmp_a[i][j].first ^ tmp_b[i][k].first) & (~low),
                      (tmp_a[i][j].first ^ tmp_b[i][k].first) | low));
      }
    }
  }
}
long long find_sum(long long l, long long r) {
  if ((l + r) & 1) {
    return ((r - l + 1) / 2) % Mod * ((l + r) % Mod) % Mod;
  }
  return ((l + r) / 2) % Mod * ((r - l + 1) % Mod) % Mod;
}
int main() {
  scanf("%d", &n_a);
  for (int i = 1; i <= n_a; i++) {
    scanf("%lld%lld", &a[i].left, &a[i].right);
  }
  scanf("%d", &n_b);
  for (int i = 1; i <= n_b; i++) {
    scanf("%lld%lld", &b[i].left, &b[i].right);
  }
  work();
  swap(n_a, n_b);
  swap(a, b);
  work();
  sort(ans.begin(), ans.end());
  long long answer = 0, l = 0, r = -1;
  for (int i = 0; i < (int)ans.size(); i++) {
    if (ans[i].first > r) {
      answer = (answer + find_sum(l, r)) % Mod;
      l = ans[i].first;
      r = ans[i].second;
    } else {
      r = max(r, ans[i].second);
    }
  }
  answer = (answer + find_sum(l, r)) % Mod;
  printf("%lld\n", answer);
  return 0;
}
