#include <bits/stdc++.h>
using namespace std;
const long long pinf = 1e18 + 4;
const long long ninf = -pinf;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, s, k, x;
    long long ans = INT_MAX;
    set<long long> S;
    cin >> n >> s >> k;
    for (long long i = 0; i < k; i++) cin >> x, S.insert(x);
    for (long long i = s; i <= n; i++)
      if (S.find(i) == S.end()) {
        ans = min(ans, i - s);
        break;
      }
    for (long long i = s - 1; i > 0; i--)
      if (S.find(i) == S.end()) {
        ans = min(ans, s - i);
        break;
      }
    cout << ans << endl;
  }
}
