#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, s, k, x;
  cin >> t;
  map<int, bool> m;
  while (t--) {
    m.clear();
    cin >> n >> s >> k;
    for (int i = 0; i < k; i++) {
      cin >> x;
      m[x] = true;
    }
    int res = 1000000000;
    for (int ii = s; ii <= n; ii++) {
      if (m[ii] == false) {
        res = ii - s;
        break;
      }
    }
    for (int l = s; l >= 1; l--) {
      if (m[l] == false) {
        res = min(res, s - l);
        break;
      }
    }
    cout << res << endl;
  }
  return 0;
}
