#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 10, Mod = 1e9 + 7;
map<long long, long long> Mark;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  for (long long i = 1; i <= t; i++) {
    long long n, s, k;
    cin >> n >> s >> k;
    for (long long j = 1; j <= k; j++) {
      long long x;
      cin >> x;
      Mark[x] = i;
    }
    long long mn = Mod;
    for (long long j = max(1ll, s - k - 1); j <= min(n, s + k + 1); j++)
      if (Mark[j] != i) mn = min(mn, abs(j - s));
    cout << mn << '\n';
  }
  return 0;
}
