#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
long long MOD = 1e9 + 7;
long long mpow(long long a, long long b, long long p) {
  if (b == 0) return 1;
  long long t1 = mpow(a, b / 2, p);
  t1 *= t1;
  t1 %= p;
  if (b % 2) t1 *= a;
  t1 %= p;
  return t1;
}
void solve() {
  long long n, k, s;
  cin >> n >> s >> k;
  long long c, a[3001] = {0};
  for (long long i = 0; i < k; i++) {
    cin >> c;
    if (abs(c - s) <= 1500) a[1500 + c - s] = 1;
  }
  long long t1, t2;
  for (long long i = 1500; i < 3000; i++) {
    if (a[i] == 0) {
      t1 = i - 1500;
      break;
    }
  }
  if (t1 + s > n) t1 = 1e18;
  for (long long i = 1499; i >= 0; i--) {
    if (a[i] == 0) {
      t2 = 1500 - i;
      break;
    }
  }
  if (t2 >= s) t2 = 1e18;
  cout << min(t2, t1) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
