#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
const long long INF = 2000000000000000;
long long n, m = 0, t, x, y, min1 = INF, max1 = 0, k, c, d, p;
long long a[N], b[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t;
  for (int j = 0; j < t; j++) {
    cin >> n;
    max1 = 0;
    min1 = INF;
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      if (x > max1) max1 = x;
      if (y < min1) min1 = y;
    }
    cout << max(max1 - min1, m) << endl;
  }
  return 0;
}
