#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6;
using namespace std;
long long a[MAXN];
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, s, k;
    cin >> n >> s >> k;
    for (long long i = 0; i < k; i++) {
      cin >> a[i];
    }
    sort(a, a + k);
    if (!binary_search(a, a + k, s)) {
      cout << "0\n";
    } else {
      for (long long i = 1; i <= k; i++) {
        if (s + i <= n && !binary_search(a, a + k, s + i)) {
          cout << i << endl;
          break;
        }
        if (s - i > 0 && !binary_search(a, a + k, s - i)) {
          cout << i << endl;
          break;
        }
      }
    }
  }
  return 0;
}
