#include <bits/stdc++.h>
using namespace std;
map<int, bool> a;
void lol() {
  int n, s, k;
  a.clear();
  cin >> n >> s >> k;
  for (int x, i = 1; i <= k; i++) {
    cin >> x;
    a[x] = 1;
  }
  int o1, o2;
  o1 = o2 = s;
  while (a[o1] == 1) o1--;
  while (a[o2] == 1) o2++;
  if (o1 == 0) {
    cout << o2 - s << "\n";
  } else if (o2 == n + 1) {
    cout << s - o1 << "\n";
  } else
    cout << min(s - o1, o2 - s) << "\n";
}
int main() {
  int n;
  cin >> n;
  for (; n; n--) {
    lol();
  }
}
