#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> h[13000010];
long long l1[110], r1[110], l2[110], r2[110], n, m, tt;
inline long long rd() {
  long long x = 0;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x;
}
inline void modify(long long l, long long len, long long flag) {
  h[++tt] = pair<long long, long long>(l, flag);
  h[++tt] = pair<long long, long long>(l + len, -flag);
}
inline void gao(long long n, long long m, long long flag) {
  n++;
  m++;
  long long now = 0;
  for (int i = 60; ~i; i--) {
    long long h1 = (n & ((1LL << i) - 1)), h2 = (m & ((1LL << i) - 1));
    if ((n >> i) & 1) modify(now ^ (m & (1LL << i)), 1LL << i, flag * h2);
    if ((m >> i) & 1) modify(now ^ (n & (1LL << i)), 1LL << i, flag * h1);
    if ((n >> i) & (m >> i) & 1) modify(now, 1LL << i, flag << i);
    now ^= (n & (1LL << i)) ^ (m & (1LL << i));
  }
}
inline long long calc(long long l, long long r) {
  long long h1 = l + r, h2 = r - l + 1;
  if (h1 & 1) return h1 % 998244353LL * ((h2 >> 1) % 998244353LL) % 998244353LL;
  return (h1 >> 1) % 998244353LL * (h2 % 998244353LL) % 998244353LL;
}
int main() {
  srand(time(NULL));
  n = rd();
  for (int i = 1; i <= n; i++) l1[i] = rd(), r1[i] = rd();
  m = rd();
  for (int i = 1; i <= m; i++) l2[i] = rd(), r2[i] = rd();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      gao(r1[i], r2[j], 1);
      gao(r1[i], l2[j] - 1, -1);
      gao(l1[i] - 1, r2[j], -1);
      gao(l1[i] - 1, l2[j] - 1, 1);
    }
  sort(h + 1, h + tt + 1);
  long long now = 0, ans = 0;
  long long mod1 = (long long)rand() + 1000000000;
  for (int i = 1; i < tt; i++) {
    now = (now + h[i].second) % mod1;
    if (now) ans += calc(h[i].first, h[i + 1].first - 1);
  }
  printf("%lld\n", ans % 998244353LL);
  return 0;
}
