#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;
    map<long long, long long> no;
    for (long long i = 1; i <= k; i++) {
      long long tmp;
      cin >> tmp;
      no[tmp]++;
    }
    long long cnt1 = INT_MAX;
    long long cnt2 = INT_MAX;
    for (long long i = s; i <= n; i++) {
      if (no[i] == 0) {
        cnt1 = i - s;
        break;
      }
    }
    for (long long i = s; i > 0; i--) {
      if (no[i] == 0) {
        cnt2 = s - i;
        break;
      }
    }
    cout << min(cnt1, cnt2) << endl;
  }
  return 0;
}
