#include <bits/stdc++.h>
using namespace std;
long double PI = acosl(-1);
bool compare_int(int a, int b) { return (a > b); }
bool compare_string(string a, string b) { return a.size() < b.size(); }
bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second == b.second)
    return a.first > b.first;
  else
    return (a.second > b.second);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, n, x, y;
  cin >> t;
  while (t--) {
    vector<int> xx, yy;
    cin >> n;
    int kace = INT_MAX;
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      xx.push_back(x);
      yy.push_back(y);
    }
    sort(xx.begin(), xx.end());
    sort(yy.begin(), yy.end());
    cout << max(*max_element(xx.begin(), xx.end()) -
                    *min_element(yy.begin(), yy.end()),
                0)
         << endl;
  }
}
