#include <bits/stdc++.h>
bool ok = false;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, s, k, b = 0, c = 0;
    set<long long int> st;
    cin >> n >> s >> k;
    long long int a[k];
    for (long long int(i) = 0; (i) < (k); ++(i)) {
      cin >> a[i];
      st.insert(a[i]);
    }
    if (st.find(s) == st.end()) {
      cout << "0\n";
    } else {
      b = n, c = n;
      for (long long int i = s + 1; i <= n; i++) {
        if (st.find(i) == st.end()) {
          b = i - s;
          break;
        }
      }
      for (long long int i = s - 1; i >= 1; i--) {
        if (st.find(i) == st.end()) {
          c = s - i;
          break;
        }
      }
      cout << min(b, c) << endl;
    }
  }
  return 0;
}
