#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& cout, vector<T> V) {
  cout << "[ ";
  for (auto v : V) cout << v << ' ';
  return cout << ']';
}
template <class L, class R>
ostream& operator<<(ostream& cout, pair<L, R> P) {
  return cout << '(' << P.x << ',' << P.y << ')';
}
void solve() {
  long long int n, s, k, a;
  cin >> n >> s >> k;
  set<long long int> ss;
  for (long long int i = 0; i < k; i++) {
    cin >> a;
    ss.insert(a);
  }
  if (ss.find(s) == ss.end()) {
    cout << "0\n";
    return;
  }
  for (long long int i = 1; i <= 1000; i++) {
    if (s + i <= n && ss.find(s + i) == ss.end()) {
      cout << i << "\n";
      return;
    } else if (s - i > 0 && ss.find(s - i) == ss.end()) {
      cout << i << "\n";
      return;
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
