#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, t;
  cin >> t;
  long long int n, s, k, pr, step, step1, z;
  long long int in;
  for (i = 0; i < t; i++) {
    cin >> n >> s >> k;
    vector<long long int> A;
    pr = 0, step = 0, step1 = 0;
    for (j = 0; j < k; j++) {
      cin >> z;
      A.push_back(z);
    }
    sort(A.begin(), A.end());
    for (j = 0; j < k; j++) {
      if (A.at(j) == s) {
        pr = 1;
        in = j;
      }
    }
    if (pr == 0) {
      cout << "0\n";
      continue;
    }
    for (j = in; A.at(j) > A.at(0); j--) {
      if ((A.at(j) - A.at(j - 1)) > 1) {
        step = A.at(in) - (A.at(j) - 1);
        break;
      }
    }
    step1 = step;
    for (j = in; j < k - 1; j++) {
      if ((A.at(j + 1) - A.at(j)) > 1) {
        step = (A.at(j) + 1) - A.at(in);
        break;
      }
    }
    if ((step < step1 || step1 == 0) && step != 0) {
      step1 = step;
    }
    if ((((A.at(in) - (A.at(0) - 1))) && A.at(0) - 1 > 0)) {
      step = A.at(in) - (A.at(0) - 1);
    }
    if ((step < step1 || step1 == 0) && step != 0) {
      step1 = step;
    }
    if (((((A.at(k - 1) + 1) - A.at(in))) && A.at(k - 1) + 1 <= n)) {
      step = ((A.at(k - 1) + 1) - A.at(in));
    }
    if ((step < step1 || step1 == 0) && step != 0) {
      step1 = step;
    }
    cout << step1 << "\n";
  }
}
