#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  cout << max(0, -b[0] + a[n - 1]) << endl;
}
signed main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
