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;
void make_unique(vector<pair<long long, long long> >& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
struct Segments {
  static const int LOG = 61;
  const long long OFF = 1LL << (LOG - 1);
  int n;
  vector<pair<long long, long long> > S[LOG], T[LOG];
  void insert(long long l, long long r, long long lo, long long hi, int i) {
    if (r <= lo || hi <= l) return;
    T[i].push_back({lo, hi});
    if (l <= lo && hi <= r) {
      S[i].push_back({lo, hi});
    } else {
      long long mid = (lo + hi) / 2;
      insert(l, r, lo, mid, i + 1);
      insert(l, r, mid, hi, i + 1);
    }
  }
  void process() {
    cin >> n;
    for (int i = 0; i < n; i++) {
      long long l, r;
      cin >> l >> r;
      insert(l, r + 1, 0, OFF, 0);
    }
    for (int i = 0; i < LOG; i++) {
      make_unique(S[i]);
      make_unique(T[i]);
    }
  }
} A, B;
vector<pair<long long, long long> > V;
void calc(const Segments& X, const Segments& Y) {
  for (int i = 0; i < Segments::LOG; i++)
    for (auto p : X.S[i])
      for (auto q : Y.T[i]) {
        long long l = p.first ^ q.first;
        long long r = l + p.second - p.first;
        V.push_back({l, r});
      }
}
bool cmp(const pair<long long, long long>& x,
         const pair<long long, long long>& y) {
  if (x.first == y.first) return x.second > y.second;
  return x.first < y.first;
}
const int MOD = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  A.process();
  B.process();
  calc(A, B);
  calc(B, A);
  sort(V.begin(), V.end(), cmp);
  long long hi = -1;
  long long sol = 0;
  for (auto p : V) {
    if (p.second <= hi) continue;
    hi = p.second;
    if (p.first + 1 == p.second)
      sol = (sol + p.first) % MOD;
    else
      sol = (sol + (((p.second - p.first) / 2) % MOD) *
                       ((p.first + p.second - 1) % MOD)) %
            MOD;
  }
  cout << sol;
  return 0;
}
