You are given an array consisting of n integers a_1, a_2, ..., a_n. Initially a_x = 1, all other elements are equal to 0.

You have to perform m operations. During the i-th operation, you choose two indices c and d such that l_i ≤ c, d ≤ r_i, and swap a_c and a_d.

Calculate the number of indices k such that it is possible to choose the operations so that a_k = 1 in the end.

Input

The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. Then the description of t testcases follow.

The first line of each test case contains three integers n, x and m (1 ≤ n ≤ 10^9; 1 ≤ m ≤ 100; 1 ≤ x ≤ n).

Each of next m lines contains the descriptions of the operations; the i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n).

Output

For each test case print one integer — the number of indices k such that it is possible to choose the operations so that a_k = 1 in the end.

Example

Input


3
6 4 3
1 6
2 3
5 5
4 1 2
2 4
1 2
3 3 2
2 3
1 2


Output


6
2
3

Note

In the first test case, it is possible to achieve a_k = 1 for every k. To do so, you may use the following operations:

  1. swap a_k and a_4; 
  2. swap a_2 and a_2; 
  3. swap a_5 and a_5. 



In the second test case, only k = 1 and k = 2 are possible answers. To achieve a_1 = 1, you have to swap a_1 and a_1 during the second operation. To achieve a_2 = 1, you have to swap a_1 and a_2 during the second operation.
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int mod = 998244353;
const int nag = 2e5 + 5;
template <typename T>
void add(T& a, T b) {
  a += b;
  while (a >= mod) a -= mod;
  while (a < 0) a += mod;
}
template <typename T>
void mul(T& a, T b) {
  a = a * b % mod;
}
template <typename T>
void up_self(T& a, T b) {
  a = max(a, b);
}
template <typename T>
void min_self(T& a, T b) {
  a = min(a, b);
}
string find_largest_pref_palindrome(const string& a) {
  string second = a;
  reverse(second.begin(), second.end());
  second = a + "%" + second;
  int c = 0;
  vector<int> pref(2 * ((int)a.size()) + 2);
  for (int i = 1; i < second.size(); i++) {
    while (c != 0 && second[i] != second[c]) c = pref[c - 1];
    if (second[i] == second[c]) c++;
    pref[i] = c;
  }
  return second.substr(0, c);
}
long long int binexpomodulo(long long int x, long long int y) {
  long long int res = 1;
  x %= mod;
  if (!x) return 0;
  while (y) {
    if (y & 1) {
      mul(res, x);
    }
    mul(x, x);
    y >>= 1;
  }
  return res;
}
long long int nCrInOr(long long int n, long long int r) {
  long long int res = 1;
  if (r > n - r) r = n - r;
  long long int rin = 1;
  for (long long int i = 1; i <= r; i++) rin = (rin * i) % mod;
  rin = binexpomodulo(rin, mod - 2);
  for (long long int i = 1; i <= r; i++) res = (res * (n - i + 1)) % mod;
  res = (res * rin) % mod;
  return res;
}
vector<long long int> fac, ifac;
void precompute(long long int n) {
  fac.resize(n + 1, 1);
  ifac.resize(n + 1);
  for (long long int i = 2; i <= n; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
  }
  ifac[n] = binexpomodulo(fac[n], mod - 2);
  for (long long int i = n - 1; i >= 0; i--)
    ifac[i] = (ifac[i + 1] * (i + 1)) % mod;
}
long long int nCr(long long int n, long long int r) {
  return fac[n] * (ifac[n - r]) % mod * (ifac[r]) % mod;
}
int msb_pos(long long int n) {
  int ans;
  for (int i = 0; i < 64; i++)
    if (n & (1LL << i)) ans = i + 1;
  return ans;
}
long long int totient(long long int n) {
  long long int ans = n;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ans -= (ans / i);
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n >= 2) {
    ans -= ans / n;
  }
  return ans;
}
int lis(vector<long long int> a, int n) {
  vector<long long int> dp(n + 1, 1e18);
  dp[0] = -1e18;
  for (int i = 0; i < n; i++) {
    int p = (int)(lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin());
    if (dp[p - 1] < a[i] && a[i] < dp[p]) dp[p] = a[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (dp[i] != 1e18) ans = i;
  }
  return ans;
}
bool is_prime(int n) {
  if (n == 2) return true;
  if (n & 1 ^ 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long int get_(vector<long long int>& a, int pos) {
  long long int res = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    res += a[pos];
  }
  return res;
}
void upd(vector<long long int>& a, int pos, int val) {
  for (; pos < a.size(); pos = (pos | (pos + 1))) a[pos] += val;
}
long long int lmin, rmax;
bool intersect(pair<long long int, long long int> a) {
  if (a.first < lmin && a.second >= lmin) return true;
  if (a.second > rmax && a.first <= rmax) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long int n, x, m;
    cin >> n >> x >> m;
    vector<pair<long long int, long long int>> a(m);
    lmin = -1, rmax = -1;
    int from = -1;
    for (int i = 0; i < m; i++) {
      cin >> a[i].first >> a[i].second;
      if (from == -1 && x >= a[i].first && x <= a[i].second) {
        {
          rmax = a[i].second;
          lmin = a[i].first;
          from = i;
        }
      } else if (intersect(a[i]) && rmax != -1) {
        up_self(rmax, a[i].second);
        min_self(lmin, a[i].first);
      }
    }
    if (from == -1) {
      cout << 1 << "\n";
      continue;
    }
    cout << rmax - lmin + 1 << "\n";
  }
  return 0;
}
