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>
int const MOD = 998244353;
using seg = std::pair<int64_t, int64_t>;
std::vector<seg> read_a_set() {
  int n;
  std::cin >> n;
  std::vector<seg> out(n);
  for (auto& [l, r] : out) {
    std::cin >> l >> r;
    ++r;
  }
  std::sort(begin(out), end(out));
  auto iter = begin(out);
  for (auto [l, r] : out) {
    if (iter != begin(out) and iter[-1].second >= l)
      iter[-1].second = std::max(iter[-1].second, r);
    else
      *iter++ = {l, r};
  }
  out.erase(iter, end(out));
  return out;
}
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  auto sa = read_a_set();
  auto sb = read_a_set();
  std::vector<int64_t> evinc, evdec;
  for (int z = 2; z--; std::swap(sa, sb)) {
    auto const process = [&](int64_t const l, int64_t const r) {
      auto const size = r - l;
      assert((size ^ (size - 1)) >= size);
      assert((l & -size) == l);
      auto const push = [&](int64_t i) {
        evinc.push_back(i);
        evdec.push_back(i + size);
      };
      for (auto const [l2, r2] : sb) {
        auto i = l2 & -size;
        push(l ^ i);
        i += size;
        if (i >= r2) continue;
        push(l ^ i);
        auto j = (r2 - 1) & -size;
        if (j <= i) continue;
        push(l ^ j);
        j -= size;
        if (j <= i) continue;
        push(l ^ j);
      }
    };
    for (auto [l, r] : sa) {
      for (int64_t bit = 1; l < r; bit <<= 1) {
        if (l & bit) {
          process(l, l + bit);
          l += bit;
        }
        if (r & bit) {
          process(r - bit, r);
          r -= bit;
        }
      }
      assert(l == r);
    }
  }
  assert(evinc.size() == evdec.size());
  if (evinc.size() > 20480000) return 1;
  std::sort(begin(evinc), end(evinc));
  std::sort(begin(evdec), end(evdec));
  evinc.push_back(INT64_MAX);
  evdec.push_back(INT64_MAX);
  int curdeg = 0;
  int64_t lastl = -1, ans = 0;
  auto i1 = evinc.begin();
  auto i2 = evdec.begin();
  auto const process_event = [&](int64_t x, int deg) {
    if (deg == 1 and curdeg == 0) {
      lastl = x;
    }
    curdeg += deg;
    assert(curdeg >= 0);
    if (deg == -1 and curdeg == 0) {
      assert(lastl >= 0);
      ans = (ans + (x - lastl) % MOD * ((lastl + x - 1) % MOD) % MOD *
                       ((MOD + 1) / 2)) %
            MOD;
    }
  };
  while (true) {
    if (*i1 < *i2) {
      process_event(*i1, 1);
      ++i1;
    } else if (*i2 < INT64_MAX) {
      process_event(*i2, -1);
      ++i2;
    } else
      break;
  }
  std::cout << ans << '\n';
}
