#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  scanf("%d", &test);
  while (test--) {
    int n, s, k, i, j, l, o, p;
    vector<int> star;
    scanf("%d", &n);
    scanf("%d", &s);
    scanf("%d", &k);
    map<int, int> m;
    for (i = 0; i < k; i++) {
      scanf("%d", &j);
      m[j] = 1;
    }
    o = s - 1;
    p = s + 1;
    int ans1 = 0, ans2 = 0;
    bool ok = false, po = false;
    while (o != 0) {
      if (m[o] != 1) {
        ans1++;
        ok = true;
        break;
      } else
        ans1++, o--;
    }
    while (p != n + 1) {
      if (m[p] != 1) {
        ans2++;
        po = true;
        break;
      } else
        ans2++, p++;
    }
    if (ok && po)
      ans1 = min(ans1, ans2);
    else if (po)
      ans1 = ans2;
    if (m[s] != 1) ans1 = 0;
    printf("%d", ans1);
    printf("\n");
  }
  return 0;
}
