#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, s, k, i, up, down, j, kk, d;
  cin >> t;
  while (t--) {
    cin >> n >> s >> k;
    int a[k];
    for (i = 0; i < k; i++) {
      cin >> a[i];
    }
    sort(a, a + k);
    for (i = 0; i < k; i++) {
      if (a[i] == s) {
        up = 0;
        j = i;
        kk = 0;
        while (a[j] == s + kk) {
          kk++;
          j++;
          if (j == k && s + kk == n + 1) {
            kk = INT_MAX;
            break;
          }
          if (j == k) {
            break;
          }
        }
        up = kk;
        down = 0;
        j = i;
        kk = 0;
        while (a[j] == s - kk) {
          kk++;
          j--;
          if (j == -1 && s - kk == 0) {
            kk = INT_MAX;
            break;
          }
          if (j == -1) {
            break;
          }
        }
        down = kk;
        if (up > down) {
          d = down;
        } else {
          d = up;
        }
        cout << d << "\n";
        break;
      }
      if (i == k - 1) {
        cout << 0 << "\n";
      }
    }
  }
  return 0;
}
