#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long T, n, t;
void solve() {
  long long int mx = 0, ans = 0, flag = 0, a, i, b, k, cnt = 0, cnt1 = 0,
                sum = 0, mn, p, q, s;
  cin >> n >> s >> k;
  vector<long long> v1, v2;
  for (i = 0; i < k; i++) {
    cin >> a;
    if (a == s) flag = 1;
    if (a - s > 0)
      v1.push_back(a - s);
    else if (s != a)
      v2.push_back(s - a);
  }
  sort((v1).begin(), (v1).end());
  sort((v2).begin(), (v2).end());
  if (flag == 0)
    cout << 0 << "\n";
  else {
    ans = 1;
    sum = 1;
    for (i = 0; i < v1.size(); i++) {
      if (ans == v1[i]) {
        ans++;
      } else
        break;
    }
    for (i = 0; i < v2.size(); i++) {
      if (sum == v2[i]) {
        sum++;
      } else
        break;
    }
    if (s - sum <= 0) {
      cout << ans << "\n";
    } else if (s + ans >= n) {
      cout << sum << "\n";
    } else
      cout << min(sum, ans) << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) solve();
  return 0;
}
