#include <bits/stdc++.h>
using namespace std;
vector<int> prime;
void SieveOfEratosthenes(int n) {
  bool prme[n + 1];
  memset(prme, true, sizeof(prme));
  for (int p = 2; p * p <= n; p++) {
    if (prme[p] == true) {
      for (int i = p * p; i <= n; i += p) prme[i] = false;
    }
  }
  for (int p = 2; p <= n; p++)
    if (prme[p]) prime.push_back(p);
}
void solve() {
  int n;
  cin >> n;
  vector<long long> mx, mn;
  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    mx.push_back(a);
    mn.push_back(b);
  }
  sort(mx.rbegin(), mx.rend());
  sort(mn.begin(), mn.end());
  cout << max(0ll, mx[0] - mn[0]) << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
