#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    unordered_map<long long, long long> u_mp;
    long long n, s, k;
    cin >> n >> s >> k;
    long long a[k + 1];
    for (long long i = 0; i < k; i++) {
      cin >> a[i];
      u_mp[a[i]] = 1;
    }
    long long ans = 0;
    long long i = s;
    while (i <= n) {
      if (u_mp[i] == 0) {
        break;
      }
      ans++;
      i++;
    }
    long long c = ans;
    ans = 0;
    if (i == n + 1) {
      c = INT_MAX;
    }
    i = s;
    while (i > 0) {
      if (u_mp[i] == 0) {
        break;
      }
      ans++;
      i--;
    }
    if (i == 0) {
      cout << c << endl;
    } else {
      ans = min(ans, c);
      cout << ans << endl;
    }
  }
  return 0;
}
