#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, s, k;
    cin >> n >> s >> k;
    long long a[k];
    for (long long i = 0; i < k; i++) cin >> a[i];
    map<long long, long long> mp;
    for (long long i = 0; i < k; i++) {
      mp[a[i]] = 1;
    }
    long long f = 1000000006;
    long long r = 1000000006;
    long long cnt = 0;
    for (long long i = s; i < s + k + 1 && i <= n; i++) {
      if (mp.find(i) == mp.end()) {
        f = cnt;
        break;
      } else {
        cnt++;
      }
    }
    cnt = 0;
    for (long long i = s; i > 0 && i > s - k - 1; i--) {
      if (mp.find(i) == mp.end()) {
        r = cnt;
        break;
      } else
        cnt++;
    }
    long long ans = 0;
    ans = min(f, r);
    cout << ans << endl;
  }
}
