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 maxn = 1e3 + 14, mod = 998244353, lg = 60, bs = 1e5 + 3;
struct Seg {
  long long l, r;
  bool operator<(const Seg &od) const {
    return l != od.l ? l < od.l : r > od.r;
  }
  int k() { return __builtin_ctzll(r - l); }
  int sum(long long x) {
    long long y = x - 1;
    if (x % 2)
      y /= 2;
    else
      x /= 2;
    x %= mod, y %= mod;
    return x * y % mod;
  }
  int sum() { return (sum(r) - sum(l) + mod) % mod; }
};
long long comb(long long l, long long l2, int k) {
  l2 &= (1ll << lg) - 1 ^ (1ll << k) - 1;
  return l ^ l2;
}
vector<long long> cont[2][lg];
struct HM {
  vector<long long> bu[bs];
  void insert(long long x) {
    int y = x % bs;
    if (find(bu[y].begin(), bu[y].end(), x) == bu[y].end()) bu[y].push_back(x);
  }
} hm;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  for (int i = 0; i < 2; i++) {
    int n;
    cin >> n;
    vector<Seg> v;
    while (n--) {
      long long l, r;
      cin >> l >> r;
      r++;
      v.push_back({l, r});
    }
    sort(v.begin(), v.end());
    vector<Seg> nw({v[0]});
    for (int j = 1; j < v.size(); j++) {
      if (nw.back().r < v[j].l) nw.push_back(v[j]);
      nw.back().r = max(nw.back().r, v[j].r);
    }
    for (auto [l, r] : nw) {
      while (l + (l & -l) <= r) {
        cont[i][Seg({l, l + (l & -l)}).k()].push_back(l);
        l += l & -l;
      }
      while (l != r) {
        cont[i][Seg({r ^ (r & -r), r}).k()].push_back(r ^ (r & -r));
        r ^= r & -r;
      }
    }
  }
  list<Seg> s;
  long long ans = 0;
  for (int k = lg - 1; k >= 0; k--) {
    for (auto l : cont[0][k])
      for (int k2 = k; k2 >= 0; k2--)
        for (auto l2 : cont[1][k2]) hm.insert(comb(l, l2, k));
    for (auto l : cont[1][k])
      for (int k2 = k - 1; k2 >= 0; k2--)
        for (auto l2 : cont[0][k2]) hm.insert(comb(l, l2, k));
    vector<long long> todo;
    for (int i = 0; i < bs; i++) {
      todo.insert(todo.end(), hm.bu[i].begin(), hm.bu[i].end());
      hm.bu[i].clear();
    }
    sort(todo.begin(), todo.end());
    todo.erase(unique(todo.begin(), todo.end()), todo.end());
    auto it = s.begin();
    for (auto &l : todo) {
      while (it != s.end() && it->l <= l) it++;
      if (it == s.begin() || prev(it)->r <= l) {
        Seg me = {l, l + (1ll << k)};
        s.insert(it, me);
        ans = (ans + me.sum()) % mod;
      }
    }
  }
  cout << ans << '\n';
}
