#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long p) {
  a = a % p;
  if (b == 1) return a;
  if (b == 0) return 1;
  long long temp = power(a, b / 2, p);
  long long ans = (temp * temp) % 1000000007;
  if (b & 1) ans = (a * ans) % 1000000007;
  return ans;
}
long long inv(long long a) { return power(a, 1000000007 - 2, 1000000007); }
signed main() {
  cin.sync_with_stdio(false);
  long long t;
  t = 1;
  cin >> t;
  while (t--) {
    long long n, s, k;
    cin >> n >> s >> k;
    map<long long, long long> vis;
    for (long long i = 1; i <= k; i++) {
      long long f;
      cin >> f;
      vis[f] = 1;
    }
    long long up = 1e18, down = 1e18;
    for (long long i = s; i <= n; i++) {
      if (vis.count(i) == 0) {
        up = i - s;
        break;
      }
    }
    for (long long i = s; i >= 1; i--) {
      if (vis.count(i) == 0) {
        down = s - i;
        break;
      }
    }
    cout << min(up, down) << '\n';
  }
}
