#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, s, k;
    cin >> n >> s >> k;
    vector<int> closed(k);
    for (int& x : closed) cin >> x;
    closed.push_back(0);
    closed.push_back(n + 1);
    sort(closed.begin(), closed.end());
    auto it = lower_bound(closed.begin(), closed.end(), s);
    if (*it != s) {
      cout << 0 << endl;
    } else {
      int ans = 2e9;
      for (auto j = it; j + 1 != closed.end(); j++) {
        if (*j + 1 < *(j + 1)) {
          ans = min(ans, abs(*j + 1 - s));
          break;
        }
      }
      for (auto j = it; j != closed.begin(); j--) {
        if (*j - 1 > *(j - 1)) {
          ans = min(ans, abs(*j - 1 - s));
          break;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
