#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void read(long long arr[], long long n) {
  for (long long i = 0; i < n; ++i) cin >> arr[i];
}
void printv(vector<long long> arr, long long n) {
  for (long long i = 0; i < n; ++i) cout << arr[i] << " ";
  cout << "\n";
}
void print(long long arr[], long long n) {
  for (long long i = 0; i < n; ++i) cout << arr[i] << " ";
  cout << "\n";
}
bool isPrime(long long n) {
  bool flag = 1;
  for (long long i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      flag = 0;
      break;
    }
  }
  return (flag ? 1 : 0);
}
long long power(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % 1000000007;
    x = (x * x) % 1000000007;
    y >>= 1;
  }
  return res;
}
long long a[1003];
void testcase() {
  long long n, m, i, j;
  long long s, k;
  cin >> n >> s >> k;
  read(a, k);
  long long cnt = count(a, a + k, s);
  if (!cnt) {
    cout << 0 << "\n";
    return;
  }
  map<long long, long long> M;
  long long stepf = 0, stepb = 0;
  for (i = 0; i < k; ++i) {
    M[a[i]] = 1;
  }
  for (i = s; i <= n; ++i) {
    if (M[i] == 0) break;
    ++stepf;
  }
  if (i == n + 1) stepf = 3e18;
  for (i = s; i >= 1; --i) {
    if (M[i] == 0) break;
    ++stepb;
  }
  if (i == 0) stepb = 3e18;
  cout << min(stepf, stepb) << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) testcase();
  return 0;
}
