#include <bits/stdc++.h>
using namespace std;
int t;
int n, s, k;
map<int, bool> f;
void solve() {
  cin >> n >> s >> k;
  int x;
  f.clear();
  for (int i = 1; i <= k; i++) {
    cin >> x;
    f[x] = 1;
  }
  int nr1 = 0;
  int aux = s;
  int minim = 999999999;
  while (f.count(aux) != 0 && aux > 1) {
    aux--;
    nr1++;
  }
  if (f.count(aux) == 0) minim = nr1;
  int nr2 = 0;
  aux = s;
  while (f.count(aux) != 0 && aux < n) {
    aux++;
    nr2++;
  }
  if (f.count(aux) == 0) minim = min(minim, nr2);
  cout << minim << '\n';
}
int main() {
  cin >> t;
  for (int q = 1; q <= t; q++) solve();
  return 0;
}
