#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int l = 0; l < t; l++) {
    long long n, s, k;
    cin >> n >> s >> k;
    unordered_set<long long> tilos;
    for (int i = 0; i < k; ++i) {
      long long x;
      cin >> x;
      tilos.insert(x);
    }
    for (long long i = 0; i <= k; i++) {
      if ((s + i <= n) && (tilos.find(s + i) == tilos.end())) {
        cout << i << endl;
        break;
      }
      if ((s - i >= 1) && (tilos.find(s - i) == tilos.end())) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
