#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = 3.14159265358979;
const int MAXN = 100000 + 10;
const int MAXM = 10 + 10;
int n, k, s;
int a[MAXN];
void solve() {
  for (int i = 0; i < k; i++) {
    if (a[i] == s) break;
    if (i == k - 1) {
      printf("0\n");
      return;
    }
  }
  a[k++] = 0;
  a[k++] = n + 1;
  sort(a, a + k);
  int ans = INF;
  for (int i = 1; i < k - 1; i++) {
    if (a[i] + 1 != a[i + 1]) {
      ans = min(ans, abs(s - a[i] - 1));
    }
    if (a[i] - 1 != a[i - 1]) {
      ans = min(ans, abs(s - a[i] + 1));
    }
  }
  printf("%d\n", ans);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> s >> k;
    for (int i = 0; i < k; i++) cin >> a[i];
    solve();
  }
  return 0;
}
