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;
template <typename T>
bool vmin(T& a, T b) {
  return (a > b) ? (a = b, true) : (false);
}
template <typename T>
bool vmax(T& a, T b) {
  return (a < b) ? (a = b, true) : (false);
}
template <typename T>
T smax(T x) {
  return x;
}
template <typename T, typename... K>
T smax(T a, const K&... args) {
  return max(a, smax(args...));
}
template <typename T>
T smin(T x) {
  return x;
}
template <typename T, typename... K>
T smin(T a, const K&... args) {
  return min(a, smin(args...));
}
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& z) {
  os << "(" << z.first << ", " << z.second << ')';
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& a) {
  bool isfirst = true;
  os << "{";
  for (auto z : a) {
    if (!isfirst) {
      os << ", ";
    }
    os << z;
    isfirst = false;
  }
  os << '}';
  return os;
}
const int inf = (signed)(~0u >> 2);
const long long llf = (signed long long)(~0ull >> 2);
template <typename T>
int vsize(vector<T>& x) {
  return (signed)x.size();
}
template <typename T>
void discrete(T* a, int* b, int n) {
  vector<T> v(a + 1, a + n + 1);
  sort(v.begin(), v.end());
  for (int i = 1; i <= n; i++)
    b[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
}
const int Mod = 998244353;
const int bzmax = 60;
int sum2(long long n) {
  n %= Mod;
  return ((n * (n + 1)) >> 1) % Mod;
}
int sum2(long long l, long long r) { return sum2(r) - sum2(l - 1); }
typedef class TrieNode {
 public:
  bool cov;
  TrieNode* ch[2];
} TrieNode;
TrieNode pool[62 * 205 * 4];
TrieNode* _top = pool;
TrieNode* newnode() {
  _top->cov = false;
  _top->ch[0] = _top->ch[1] = NULL;
  return _top++;
}
void insert(TrieNode*& p, long long l, long long r, long long ql,
            long long qr) {
  if (!p) {
    p = newnode();
  }
  if (l == ql && r == qr) {
    p->cov = true;
    return;
  }
  long long mid = (l + r) >> 1;
  if (qr <= mid) {
    insert(p->ch[0], l, mid, ql, qr);
  } else if (ql > mid) {
    insert(p->ch[1], mid + 1, r, ql, qr);
  } else {
    insert(p->ch[0], l, mid, ql, mid);
    insert(p->ch[1], mid + 1, r, mid + 1, qr);
  }
}
long long solve(vector<pair<TrieNode*, TrieNode*>> a, long long l,
                long long r) {
  if (a.empty()) {
    return 0;
  }
  for (auto t : a) {
    if (t.first->cov || t.second->cov) {
      return sum2(r) - sum2(l - 1);
    }
  }
  vector<pair<TrieNode*, TrieNode*>> b[2];
  for (auto t : a) {
    auto x = t.first;
    auto y = t.second;
    for (int bx = 0; bx < 2; bx++) {
      for (int by = 0; by < 2; by++) {
        if (x->ch[bx] && y->ch[by]) {
          b[bx ^ by].emplace_back(x->ch[bx], y->ch[by]);
        }
      }
    }
  }
  long long mid = (l + r) >> 1;
  long long foo = solve(b[0], l, mid);
  long long baz = solve(b[1], mid + 1, r);
  return foo + baz;
}
int na, nb;
TrieNode *rta, *rtb;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long R = (1ll << bzmax) - 1, l, r;
  cin >> na;
  for (int i = 0; i < na; i++) {
    cin >> l >> r;
    insert(rta, 0, R, l, r);
  }
  cin >> nb;
  for (int i = 0; i < nb; i++) {
    cin >> l >> r;
    insert(rtb, 0, R, l, r);
  }
  long long ans =
      solve(vector<pair<TrieNode*, TrieNode*>>{make_pair(rta, rtb)}, 0, R);
  ans %= Mod;
  if (ans < 0) {
    ans += Mod;
  }
  cout << ans << '\n';
  return 0;
}
