#include <bits/stdc++.h>
const int N = 1005;
int t;
int n, s, k;
int a[N];
bool solve(int x) {
  for (int i = 0; i < k; i++) {
    if (x == a[i]) return false;
  }
  return true;
}
int main(void) {
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d", &n, &s, &k);
    memset(a, 0, sizeof(a));
    for (int i = 0; i < k; i++) {
      scanf("%d", &a[i]);
    }
    int ans = 0;
    for (int ans = 0; ans < N; ans++) {
      int x = s + ans;
      int y = s - ans;
      if ((solve(x) && x <= n) || (solve(y) && y > 0)) {
        printf("%d\n", ans);
        break;
      }
    }
  }
  return 0;
}
