#include <bits/stdc++.h>
using namespace std;
const long long int MAXN = 1e5 + 100;
const long long int inf = 1e15;
long long int d4x[] = {1, 0, -1, 0};
long long int d4y[] = {0, 1, 0, -1};
long long int d8x[] = {1, 1, 0, -1, -1, -1, 0, 1};
long long int d8y[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  return (max(a, b) / gcd(a, b)) * min(a, b);
}
long long int powermodm(long long int x, long long int n, long long int M) {
  long long int result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % M;
    x = (x * x) % M;
    n = n / 2;
  }
  return result;
}
long long int gcdExtended(long long int a, long long int b, long long int *x,
                          long long int *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long int x1, y1;
  long long int gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long int modInverse(long long int a, long long int m) {
  long long int x, y;
  long long int g = gcdExtended(a, m, &x, &y);
  if (g != 1)
    return -1;
  else {
    long long int res = (x % m + m) % m;
    return res;
  }
}
bool isPrime(long long int a) {
  if (a == 1) return false;
  if (a == 2) return true;
  if (a % 2 == 0) return false;
  long long int root = sqrt(a);
  for (long long int i = 3; i <= (long long int)root; i += 2) {
    if (a % i == 0) return false;
  }
  return true;
}
bool isValidpt(long long int u, long long int v, long long int n,
               long long int m) {
  if (u >= 0 && v >= 0 && u < n && v < m) return true;
  return false;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int tc = 1;
  cin >> tc;
  while (tc--) {
    long long int n, s, k;
    cin >> n >> s >> k;
    long long int num;
    set<long long int> st;
    for (long long int i = 0; i < k; i++) {
      long long int num;
      cin >> num;
      st.insert(num);
    }
    long long int ans = n;
    for (long long int i = max(s - k, (long long int)1); i <= min(n, s + k);
         i++) {
      if (st.find(i) == st.end()) ans = min(ans, abs(i - s));
    }
    cout << ans << endl;
  }
}
