#include <bits/stdc++.h>
using namespace std;
using cat = long long;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int N[2];
  vector<pair<cat, cat> > S[2];
  for (int k = 0; k < 2; k++) {
    cin >> N[k];
    S[k].resize(N[k]);
    for (int i = 0; i < N[k]; i++) cin >> S[k][i].first >> S[k][i].second;
  }
  for (int k = 0; k < 2; k++) {
    sort(begin(S[k]), end(S[k]));
    int cur = 0;
    for (int i = 0; i < S[k].size(); i++) {
      if (cur && S[k][i].first <= S[k][cur - 1].second + 1)
        S[k][cur - 1].second = max(S[k][cur - 1].second, S[k][i].second);
      else
        S[k][cur++] = S[k][i];
    }
    S[k].resize(cur);
  }
  vector<cat> X[2][60], Y[2][60];
  for (int k = 0; k < 2; k++)
    for (int i = 0; i < N[k]; i++) {
      auto [l, r] = S[k][i];
      for (int d = 0; d < 60; d++) {
        if ((l >> d) & 1) {
          X[k][d].push_back(l >> d);
          l += 1LL << d;
        }
        if (l <= r && ((r >> d) & 1) == 0) {
          X[k][d].push_back(r >> d);
          r -= 1LL << d;
        }
        if (l > r) break;
      }
      for (int d = 0; d < 60; d++) {
        Y[k][d].push_back(S[k][i].first >> d);
        Y[k][d].push_back(S[k][i].second >> d);
      }
    }
  vector<cat> Z[60];
  for (int k = 0; k < 60; k++) {
    sort(begin(X[0][k]), end(X[0][k]));
    auto it = unique(begin(X[0][k]), end(X[0][k]));
    X[0][k].resize(it - begin(X[0][k]));
    sort(begin(X[1][k]), end(X[1][k]));
    it = unique(begin(X[1][k]), end(X[1][k]));
    X[1][k].resize(it - begin(X[1][k]));
    sort(begin(Y[0][k]), end(Y[0][k]));
    it = unique(begin(Y[0][k]), end(Y[0][k]));
    Y[0][k].resize(it - begin(Y[0][k]));
    sort(begin(Y[1][k]), end(Y[1][k]));
    it = unique(begin(Y[1][k]), end(Y[1][k]));
    Y[1][k].resize(it - begin(Y[1][k]));
    Z[k].reserve(X[0][k].size() * Y[1][k].size() +
                 X[1][k].size() * Y[0][k].size());
  }
  for (int k = 0; k < 60; k++)
    for (auto x : X[0][k])
      for (auto y : Y[1][k]) Z[k].push_back(x ^ y);
  for (int k = 0; k < 60; k++)
    for (auto x : Y[0][k])
      for (auto y : X[1][k]) Z[k].push_back(x ^ y);
  for (int k = 0; k < 60; k++)
    for (auto x : X[0][k])
      for (auto y : X[1][k]) Z[k].push_back(x ^ y);
  vector<pair<cat, cat> > seg;
  for (int k = 59; k >= 0; k--) {
    static vector<pair<cat, cat> > seg_next;
    seg_next.clear();
    sort(begin(Z[k]), end(Z[k]));
    int a = 0;
    for (int i = 0; i < (int)Z[k].size(); i++) {
      if (i && Z[k][i] == Z[k][i - 1]) continue;
      cat l = Z[k][i] << k;
      while (a < (int)seg.size() && seg[a].second <= l) {
        seg_next.push_back(seg[a]);
        a++;
      }
      if (a < (int)seg.size() && seg[a].first <= l) continue;
      seg_next.push_back({l, l + (1LL << k)});
    }
    while (a < (int)seg.size()) {
      seg_next.push_back(seg[a]);
      a++;
    }
    seg = seg_next;
  }
  cat mod = 998244353, ans = 0;
  for (auto [l, r] : seg) {
    cat f1 = r - l, f2 = r + l - 1;
    if (f1 % 2 == 0)
      f1 /= 2;
    else
      f2 /= 2;
    f1 %= mod, f2 %= mod;
    cerr << l << " " << r << "\n";
    ans += f1 * f2 % mod;
  }
  ans %= mod;
  cout << ans << "\n";
  return 0;
}
