#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, s, k;
    cin >> n >> s >> k;
    long long a[k];
    map<long long, long long> mp;
    for (long long i = 0; i < k; i++) {
      cin >> a[i];
      mp[a[i]] = 1;
    }
    long long ans;
    for (long long i = 0;; i++) {
      if (mp[s - i] == 0 && (s - i) > 0) {
        ans = s - i;
        break;
      }
      if (mp[s + i] == 0 && (s + i) < n + 1) {
        ans = s + i;
        break;
      }
    }
    cout << abs(s - ans) << "\n";
  }
}
