#include <bits/stdc++.h>
using namespace std;
int t;
map<long long, int> Codeforce;
void Codeforces_work() {
  long long n, s, k, pointx, pointy;
  Codeforce.clear();
  cin >> n >> s >> k;
  for (int i = 1; i <= k; i++) {
    cin >> pointx;
    Codeforce[pointx] = 1;
  }
  pointx = s, pointy = s;
  while (Codeforce[pointx]) ++pointx;
  while (Codeforce[pointy]) --pointy;
  if (pointy == 0) pointy = 0x3f3f3f3f;
  ;
  if (pointx == n + 1) pointx = 0x3f3f3f3f;
  ;
  cout << min(abs(s - pointx), abs(s - pointy)) << endl;
  ;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    Codeforces_work();
  }
  return 0;
}
