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>
using namespace std;
vector<vector<int>> comp;
vector<int> onecycle;
vector<int> clength;
vector<int> v9;
vector<int> v8;
int cycle_start;
int cycle_end;
vector<int> vbip1;
vector<int> vbip2;
void addedge(int u, int v, vector<int> adj[]) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
void dfsforconnectedcomponents(int s, vector<int> adj[], int V, int u[],
                               int &count) {
  v9.push_back(s);
  u[s] = 1;
  int i;
  for (i = 0; i < adj[s].size(); i++) {
    if (u[adj[s][i]] == 0) {
      count++;
      dfsforconnectedcomponents(adj[s][i], adj, V, u, count);
    }
  }
}
void connectedcomponents(int V, vector<int> adj[], int u[]) {
  int i;
  for (i = 1; i < V + 1; i++) {
    if (u[i] == 0) {
      int count = 1;
      dfsforconnectedcomponents(i, adj, V, u, count);
      comp.push_back(v9);
      v9.clear();
    }
  }
}
bool dfs1foronecycle(int s, int V, int color[], vector<int> adj[], int p[]) {
  color[s] = 1;
  int i;
  for (i = 0; i < adj[s].size(); i++) {
    if (color[adj[s][i]] == 0) {
      p[adj[s][i]] = s;
      if (dfs1foronecycle(adj[s][i], V, color, adj, p)) {
        return true;
      }
    } else if (color[adj[s][i]] == 1 && p[s] != adj[s][i]) {
      cycle_start = adj[s][i];
      cycle_end = s;
      return true;
    }
  }
  color[s] = 2;
  return false;
}
void cyclesusingdfs1(int V, vector<int> adj[], int color[], int p[]) {
  int i;
  for (i = 1; i < V + 1; i++) {
    if (color[i] == 0) {
      if (dfs1foronecycle(i, V, color, adj, p)) {
        int count = 1;
        i = cycle_end;
        while (i != cycle_start) {
          i = p[i];
          count++;
        }
        clength.push_back(count);
        count = 0;
      }
    }
  }
}
bool bfsbipartite(vector<int> adj[], int V) {
  int u[V + 1];
  int i;
  for (i = 0; i < V + 1; i++) {
    u[i] = 0;
  }
  int color[V + 1];
  for (i = 0; i < V + 1; i++) {
    color[i] = -1;
  }
  int s;
  for (s = 1; s < V + 1; s++) {
    if (color[s] == -1) {
      u[s] = 1;
      color[s] = 1;
      queue<int> q;
      q.push(s);
      while (!q.empty()) {
        int z = q.front();
        q.pop();
        for (i = 0; i < adj[z].size(); i++) {
          int k = adj[z][i];
          if (color[k] == -1) {
            color[k] = 1 - color[z];
            u[k] = 1;
            q.push(k);
          }
        }
      }
    }
  }
  int flag[V + 1];
  for (i = 0; i < V + 1; i++) {
    flag[i] = 0;
  }
  for (i = 1; i < V + 1; i++) {
    for (int j = 0; j < adj[i].size(); j++) {
      if (color[i] == color[adj[i][j]]) {
        return false;
      }
      if (color[adj[i][j]] == 1 && flag[adj[i][j]] == 0) {
        flag[adj[i][j]] = 1;
        vbip1.push_back(adj[i][j]);
      }
      if (color[adj[i][j]] == 0 && flag[adj[i][j]] == 0) {
        flag[adj[i][j]] = 1;
        vbip2.push_back(adj[i][j]);
      }
    }
  }
  return true;
}
void bfs1(int V, int s, vector<int> adj[], int d[], int anc[], int u[]) {
  int i;
  d[s] = 0;
  u[s] = 1;
  anc[s] = -1;
  v8.push_back(s);
  queue<int> q;
  q.push(s);
  vector<int> v;
  while (!q.empty()) {
    int z = q.front();
    q.pop();
    for (i = 0; i < adj[z].size(); i++) {
      int k = adj[z][i];
      if (u[adj[z][i]] == 0) {
        d[k] = d[z] + 1;
        anc[k] = z;
        u[k] = 1;
        q.push(k);
      }
    }
  }
}
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int binarySearch(vector<long long> arr, int l, int r, long long x) {
  if (r >= l) {
    int mid = l + (r - l) / 2;
    if (arr[mid] == x) return mid;
    if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);
    return binarySearch(arr, mid + 1, r, x);
  }
  return l;
}
string bin(long long x, long long n) {
  string s = "";
  while (x != 0) {
    if (x % 2 == 0) {
      s.push_back('0');
    } else {
      s.push_back('1');
    }
    x = x / 2;
  }
  int l = s.length();
  int i;
  for (i = 0; i < n - l; i++) {
    s.push_back('0');
  }
  reverse(s.begin(), s.end());
  return s;
}
vector<long long> prime(int n) {
  int prime[n + 1];
  for (int i = 0; i < n + 1; i++) prime[i] = 1;
  for (int p = 2; p * p <= n + 1; p++) {
    if (prime[p] == 1) {
      for (int i = p * p; i <= n + 1; i += p) prime[i] = 0;
    }
  }
  vector<long long> v;
  long long i;
  for (i = 2; i < n + 1; i++) {
    if (prime[i] == 1) {
      v.push_back(i);
    }
  }
  return v;
}
int nCrModp(int n, int r, int p) {
  if (r > n - r) r = n - r;
  int C[r + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p;
  }
  return C[r];
}
int ispal(string s) {
  int i;
  int l = s.length();
  int flag = 0;
  for (i = 0; i < l / 2; i++) {
    if (s[i] != s[l - 1 - i]) {
      flag = 1;
      break;
    }
  }
  if (flag == 1) {
    return 0;
  }
  return 1;
}
int fun(int x, int y, int m) { return m * x + y + 1; }
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, x, m;
    cin >> n >> x >> m;
    long long i;
    long long min = INT_MAX;
    long long max = INT_MIN;
    int flag = 0;
    while (m--) {
      long long a, b;
      cin >> a >> b;
      if (flag == 0) {
        if (x >= a && x <= b) {
          flag = 1;
          min = a;
          max = b;
        }
      }
      if (flag == 1) {
        if ((a >= min && a <= max) || (b >= min && b <= max) ||
            (a <= min && b >= max)) {
          if (a < min) {
            min = a;
          }
          if (b > max) {
            max = b;
          }
        }
      }
    }
    if (flag == 0) {
      cout << 1 << endl;
    } else {
      cout << max - min + 1 << endl;
    }
  }
}
