#include <bits/stdc++.h>
using namespace std;
long long int ar[1002], k;
long long int solvel(long long int s) {
  long long int mid, l = 1, r = s, ans = 0;
  while (l <= r) {
    mid = (l + r) / 2;
    if (s - mid == ar[s] - ar[mid])
      r = mid - 1;
    else
      l = mid + 1;
  }
  ans = ar[l] - 1;
  if (ans > 0) return ans;
  return -10000000001;
}
long long int solver(long long int s, long long int n) {
  long long int mid, ans = 0, l = s, r = k;
  while (l <= r) {
    mid = (l + r) / 2;
    if (mid - s == ar[mid] - ar[s])
      l = mid + 1;
    else
      r = mid - 1;
  }
  ans = ar[r] + 1;
  if (ans <= n) return ans;
  return 10000000001;
}
int main() {
  long long int t, n, s, l, r, i;
  cin >> t;
  while (t--) {
    long long int check = 0;
    cin >> n >> s >> k;
    for (i = 1; i <= k; i++) {
      cin >> ar[i];
    }
    sort(ar + 1, ar + k + 1);
    check = find(ar + 1, ar + 1 + k, s) - ar;
    if (check > k)
      cout << 0 << endl;
    else {
      l = solvel(check);
      r = solver(check, n);
      cout << min(s - l, r - s) << endl;
    }
  }
  return 0;
}
