#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, s, k;
  cin >> n >> s >> k;
  set<long long int> st;
  for (long long int i = 0; i < k; i++) {
    long long int x;
    cin >> x;
    st.insert(x);
  }
  if (st.find(s) == st.end()) {
    cout << 0 << "\n";
    return;
  }
  long long int ans = 1e18 + 7;
  for (long long int i = s - 1; i >= max((long long int)1, s - 1001); i--) {
    if (st.find(i) == st.end()) {
      ans = min(ans, s - i);
      break;
    }
  }
  for (long long int i = s + 1; i <= min(n, s + 1001); i++) {
    if (st.find(i) == st.end()) {
      ans = min(ans, i - s);
      break;
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
