#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, s;
    int k;
    cin >> n >> s >> k;
    set<long long> m;
    for (int i = 1; i <= k; i++) {
      long long x;
      cin >> x;
      m.insert(x);
    }
    long long st1 = 0, st2 = 0;
    long long i = s, j = s;
    if (m.find(s) == m.end()) {
      cout << "0\n";
    } else {
      while (m.find(i) != m.end()) {
        i--;
        st1++;
      }
      while (m.find(j) != m.end()) {
        j++;
        st2++;
      }
      if (i == 0)
        cout << st2 << "\n";
      else if (j > n)
        cout << st1 << '\n';
      else
        cout << min(st1, st2) << "\n";
    }
  }
  return 0;
}
