#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double EPS = 1e-7;
const ll INF = 1000000000;
const string input = "minions.in", output = "minions.out";
const bool fileInput = false;
bool hasElement(vector<ll>& a, ll el) {
  return find(a.begin(), a.end(), el) != a.end();
}
int main() {
  if (fileInput) {
    freopen(input.c_str(), "r", stdin);
    freopen(output.c_str(), "w", stdout);
  } else {
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
  ll countTests;
  cin >> countTests;
  while (countTests--) {
    ll n, s, k;
    cin >> n >> s >> k;
    vector<ll> a(k);
    for (ull i = 0; i < k; ++i) {
      cin >> a[i];
    }
    for (int i = 0; i <= k; i++) {
      if (s - i >= 1 && !hasElement(a, s - i)) {
        cout << i << '\n';
        break;
      }
      if (s + i <= n && !hasElement(a, s + i)) {
        cout << i << '\n';
        break;
      }
    }
  }
  return 0;
}
