#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int i, n, t, s, k, x, y;
  map<int, bool> mp;
  cin >> t;
  while (t--) {
    cin >> n >> s >> k;
    mp.clear();
    while (k--) {
      cin >> x;
      mp[x] = 1;
    }
    x = y = 0;
    for (i = s; i > 0; i--) {
      if (mp.find(i) == mp.end()) break;
      ++x;
    }
    if (i == 0) x = INT_MAX;
    for (i = s; i <= n; i++) {
      if (mp.find(i) == mp.end()) break;
      ++y;
    }
    if (i > n) y = INT_MAX;
    cout << min(x, y) << '\n';
  }
  return 0;
}
