#include <bits/stdc++.h>
using namespace std;
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const long long MAXN = 3e5 + 123;
const long double EPS = 1e-12;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
long long n, s, k, ans;
map<long long, bool> u;
void solve() {
  ans = INF;
  u.clear();
  cin >> n >> s >> k;
  for (int i = 1, x; i <= k; ++i) {
    cin >> x;
    u[x] = 1;
  }
  if (u[s] == 0) {
    cout << 0 << '\n';
    return;
  }
  for (auto &&[x, y] : u) {
    if (u.count(x - 1) == 0 && x - 1 >= 1) {
      ans = min(ans, abs(x - 1 - s));
    }
    if (u.count(x + 1) == 0 && x + 1 <= n) {
      ans = min(ans, abs(x + 1 - s));
    }
  }
  cout << ans << '\n';
}
int main() {
  faster();
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
