#include <bits/stdc++.h>
using namespace std;
int t, s, k, n;
int x;
void d();
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    d();
  }
  return 0;
}
void d() {
  scanf("%d%d%d", &n, &s, &k);
  map<int, int> a;
  for (int j = 1; j <= k; j++) {
    scanf("%d", &x);
    a[x] = 1;
  }
  long long int up = 1000000, down = 1000000;
  long long int p = s;
  while (a[p] && p <= n) {
    p++;
  }
  if (p <= n) up = p - s;
  p = s;
  while (a[p] && p > 0) {
    p--;
  }
  if (p > 0) down = s - p;
  printf("%d\n", (up > down) ? down : up);
}
