#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, s, k;
    cin >> n >> s >> k;
    int a[k];
    map<int, int> make_pair;
    for (int i = 1; i <= k; i++) {
      cin >> a[i];
      make_pair[a[i]]++;
    }
    int ans = INT_MAX;
    for (int i = s; i <= n; i++) {
      if (make_pair.count(i) == 0) {
        ans = min(ans, i - s);
        break;
      }
    }
    for (int i = s; i >= 1; i--) {
      if (make_pair.count(i) == 0) {
        ans = min(ans, s - i);
        break;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
