#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, s, k, l = 0, r = 0;
    cin >> n >> s >> k;
    l = s;
    r = s;
    vector<long long int> v(k);
    for (long long int i = 0; i < k; i++) {
      cin >> v[i];
    }
    while (find(v.begin(), v.end(), l) != v.end()) {
      if (l == 1) {
        l--;
        break;
      }
      l--;
    }
    while (find(v.begin(), v.end(), r) != v.end()) {
      if (r == n) {
        r = n + 1;
        break;
      }
      r++;
    }
    if (l == 0)
      cout << abs(r - s) << '\n';
    else if (r == n + 1)
      cout << abs(l - s) << '\n';
    else
      cout << min(abs(l - s), abs(r - s)) << '\n';
  }
  return 0;
}
