#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int t;
  cin >> t;
  while (t--) {
    int a, b, c, x, flag = 0, flag1 = 0, flag2 = 0, h, u;
    cin >> a >> b >> c;
    vector<int> vec(c);
    vector<int> arr1;
    for (int i = 0; i < c; i++) {
      cin >> x;
      if (x == b) flag = -1;
      vec[i] = x;
    }
    sort(vec.begin(), vec.end());
    auto it = std::find(vec.begin(), vec.end(), b);
    int d = distance(vec.begin(), it);
    if (flag != -1)
      cout << 0 << endl;
    else {
      for (int i = d; i < c - 1; i++) {
        if (vec[i + 1] - vec[i] != 1) {
          h = (vec[i] - b + 1);
          flag1 = -1;
          break;
        }
      }
      if (flag1 != -1) {
        if (vec[c - 1] != a)
          h = vec[c - 1] - b + 1;
        else
          h = 1000000000;
      }
      for (int i = d; i > 0; i--) {
        if (vec[i] - vec[i - 1] != 1) {
          u = (b - vec[i] + 1);
          flag2 = -1;
          break;
        }
      }
      if (flag2 != -1) {
        if (vec[0] != 1)
          u = (b - vec[0] + 1);
        else
          u = 1000000;
      }
      cout << min(u, h) << endl;
    }
  }
}
