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