#include <bits/stdc++.h>
using namespace std;
const long long Maxn = 5e3 + 10;
const long long INF = 1e16;
unordered_map<long long, bool> m;
set<long long> S;
int main() {
  long long T;
  scanf("%lld", &T);
  while (T--) {
    S.clear();
    m.clear();
    long long n, s, k;
    cin >> n >> s >> k;
    for (long long i = 1; i <= k; i++) {
      long long xx;
      cin >> xx;
      m[xx] = 1;
      S.insert(xx);
    }
    if (!m[s]) {
      cout << "0" << endl;
      continue;
    }
    auto it = S.lower_bound(s);
    auto it1 = it;
    if (it1 != S.begin()) it1--;
    long long now = s, ans = INF;
    if (s != 1)
      if (!m[s - 1]) ans = min(ans, 1ll);
    while (it1 != S.begin()) {
      long long temp = (*it1);
      if (abs(now - temp) > 1) {
        ans = min(ans, abs(s - (now - 1)));
        break;
      }
      now = temp;
      it1--;
    }
    if ((*it1) != 1) {
      if (now != 1) {
        if (!m[now - 1])
          ans = min(ans, abs(s - (now - 1)));
        else
          ans = min(ans, s - ((*it1) - 1));
      }
    } else {
      if (now != 1) {
        if (!m[now - 1]) ans = min(ans, abs(s - (now - 1)));
      }
    }
    now = s;
    while (it != S.end()) {
      long long temp = (*it);
      if (abs(now - temp) > 1) {
        ans = min(ans, abs(s - (now + 1)));
        break;
      }
      now = temp;
      it++;
    }
    it--;
    if ((*it) != n) ans = min(ans, abs(s - ((*it) + 1)));
    cout << ans << endl;
  }
  return 0;
}
