#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 4;
const long long MAXN = 1000001;
long long power(long long x, unsigned int y) {
  long long temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if ((y % 2) == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  map<long long, long long> mp1;
  vector<long long> v;
  while (t--) {
    v.clear();
    mp1.clear();
    long long n, s, k;
    cin >> n >> s >> k;
    long long x;
    for (long long i = 0; i < (long long)k; i++) {
      cin >> x;
      mp1[x] = 1;
      v.push_back(x);
    }
    long long best = LONG_MAX;
    long long curr;
    if (mp1[s] == 0) {
      cout << 0 << endl;
      continue;
    }
    for (long long i = 0; i < (long long)v.size(); i++) {
      for (long long j = v[i] - 1; j > 0; j--) {
        if (mp1[j] == 1)
          break;
        else {
          best = min(best, llabs(j - s));
          break;
        }
      }
      for (long long j = v[i] + 1; j <= n; j++) {
        if (mp1[j] == 1)
          break;
        else {
          best = min(best, llabs(j - s));
          break;
        }
      }
    }
    cout << best << endl;
  }
  return 0;
}
