#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 7;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
void solve() {
  long long n, s, k;
  cin >> n >> s >> k;
  set<long long> a;
  for (long long i = 0; i < k; i++) {
    long long x;
    cin >> x;
    a.insert(x);
  }
  for (long long i = 0; i <= 2000; i++) {
    if (s + i <= n && a.find(s + i) == a.end()) {
      cout << i << '\n';
      break;
    }
    if (s - i > 0 && a.find(s - i) == a.end()) {
      cout << i << '\n';
      break;
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  clock_t beg = clock();
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}
