#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int dio[N];
int find(int x, int n) {
  int l = 1, r = n, mid, ans = 0;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (dio[mid] < x)
      l = mid + 1;
    else if (dio[mid] > x)
      r = mid - 1;
    else {
      ans = mid;
      break;
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  int T;
  cin >> T;
  while (T--) {
    int n, s, k, ans = 1e9 + 7;
    cin >> n >> s >> k;
    for (int i = 1; i <= k; i++) cin >> dio[i];
    sort(dio + 1, dio + 1 + k);
    for (int i = s; i >= 1; i--)
      if (!find(i, k)) {
        ans = s - i;
        break;
      }
    for (int i = s + 1; i <= n; i++) {
      if (i - s >= ans) break;
      if (!find(i, k)) {
        ans = i - s;
        break;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
