#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long m) {
  if (y == 0) return 1;
  long long p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long modInverse(long long a, long long m) { return power(a, m - 2, m); }
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, s, k, ans1 = 1000000007, ans2 = 1000000007;
    cin >> n >> s >> k;
    long long a[k];
    set<long long> ss;
    for (long long i = 0; i < k; i++) {
      cin >> a[i];
      ss.insert(a[i]);
    }
    for (long long i = s; i <= min(n, s + 1005); i++) {
      if (ss.find(i) == ss.end()) {
        ans1 = i - s;
        break;
      }
    }
    for (long long i = s - 1; i >= max((long long)1, s - 1005); i--) {
      if (ss.find(i) == ss.end()) {
        ans2 = s - i;
        break;
      }
    }
    cout << min(ans1, ans2) << endl;
  }
}
