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 long long LB = 0;
const long long RB = (1LL << 60LL) - 1;
vector<tuple<int, long long, long long>> reduced[2];
vector<pair<long long, long long>> all[2][65];
inline void insert(int id, int depth, long long l, long long r, long long qs,
                   long long qe) {
  if (l > qe || r < qs) {
    return;
  }
  all[id][depth].push_back({l, r});
  if (l >= qs && r <= qe) {
    reduced[id].push_back(make_tuple(depth, l, r));
    return;
  }
  long long mid = (l + r) / 2;
  insert(id, depth - 1, l, mid, qs, qe);
  insert(id, depth - 1, mid + 1, r, qs, qe);
}
int main() {
  int na;
  cin >> na;
  for (int i = 0; i < na; i++) {
    long long l, r;
    cin >> l >> r;
    insert(0, 60, LB, RB, l, r);
  }
  int nb;
  cin >> nb;
  for (int i = 0; i < nb; i++) {
    long long l, r;
    cin >> l >> r;
    insert(1, 60, LB, RB, l, r);
  }
  vector<pair<long long, long long>> unnormalized;
  for (int cur = 0; cur < 2; cur++) {
    for (auto [depth, l1, r1] : reduced[cur]) {
      for (auto [l2, r2] : all[1 - cur][depth]) {
        long long l_res = (l1 ^ l2) & (RB ^ ((1LL << depth) - 1));
        long long r_res = l_res + (1LL << depth) - 1;
        unnormalized.push_back({l_res, r_res});
      }
    }
  }
  assert(unnormalized.size() <= 100 * 100 * 60 * 8);
  sort(unnormalized.begin(), unnormalized.end());
  vector<pair<long long, long long>> normalized_intervals;
  for (auto [l, r] : unnormalized) {
    if (normalized_intervals.empty() ||
        normalized_intervals.back().second < l) {
      normalized_intervals.push_back({l, r});
    } else {
      normalized_intervals.back().second =
          max(normalized_intervals.back().second, r);
    }
  }
  long long sol = 0;
  for (auto [l, r] : normalized_intervals) {
    long long reduced_r = r % MOD;
    long long reduced_l = l % MOD;
    sol += (((reduced_r * (reduced_r + 1)) / 2) % MOD);
    sol %= MOD;
    sol -= (((reduced_l * (reduced_l - 1)) / 2) % MOD);
    sol += MOD;
    sol %= MOD;
  }
  cout << sol << endl;
}
