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;
using ll = long long;
struct Seg {
  ll start;
  ll finish;
  ll size() const { return finish - start; }
  bool contains(const Seg &s) const {
    return start <= s.start && s.finish <= finish;
  }
};
struct Node {
  Node *l = nullptr;
  Node *r = nullptr;
  bool full = false;
};
void update(Node *n, const Seg &sn, const Seg &su) {
  if (su.contains(sn)) {
    n->full = true;
    return;
  }
  ll mid = (sn.start + sn.finish) >> 1;
  if (su.start < mid) {
    if (n->l == nullptr) {
      n->l = new Node;
    }
    update(n->l, Seg{sn.start, mid}, su);
  }
  if (mid < su.finish) {
    if (n->r == nullptr) {
      n->r = new Node;
    }
    update(n->r, Seg{mid, sn.finish}, su);
  }
}
const ll M = 998244353ll;
ll segSum(const Seg &s) {
  ll x = s.start + s.finish - 1;
  ll y = s.size();
  if (y & 1) {
    x >>= 1;
  } else {
    y >>= 1;
  }
  x %= M;
  y %= M;
  return x * y % M;
}
using pnn = pair<Node *, Node *>;
using vpnn = vector<pnn>;
ll calc(const vpnn &v, const Seg &s) {
  for (auto &p : v) {
    if (p.first->full || p.second->full) {
      return segSum(s);
    }
  }
  ll sol = 0;
  ll mid = (s.start + s.finish) >> 1;
  {
    vpnn vl;
    for (const pnn &p : v) {
      if (p.first->l && p.second->l) {
        vl.emplace_back(p.first->l, p.second->l);
      }
      if (p.first->r && p.second->r) {
        vl.emplace_back(p.first->r, p.second->r);
      }
    }
    if (!vl.empty()) {
      sol += calc(vl, Seg{s.start, mid});
    }
  }
  {
    vpnn vr;
    for (const pnn &p : v) {
      if (p.first->l && p.second->r) {
        vr.emplace_back(p.first->l, p.second->r);
      }
      if (p.first->r && p.second->l) {
        vr.emplace_back(p.first->r, p.second->l);
      }
    }
    if (!vr.empty()) {
      sol += calc(vr, Seg{mid, s.finish});
    }
  }
  return sol % M;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  auto inputSet = []() {
    auto *n = new Node;
    int ct;
    cin >> ct;
    while (ct--) {
      ll i, j;
      cin >> i >> j;
      update(n, Seg{0, 1ll << 60}, Seg{i, j + 1});
    }
    return n;
  };
  Node *a = inputSet();
  Node *b = inputSet();
  vpnn v = {{a, b}};
  cout << calc(v, Seg{0, 1ll << 60}) << endl;
  return 0;
}
