#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, s, k, i, j, q, ans = 1e10;
    cin >> n >> s >> k;
    map<long long, long long> closed;
    for (i = 0; i < k; i++) cin >> q, closed[q]++;
    j = s;
    while (j <= n && closed[j]) j++;
    if (j <= n) ans = j - s;
    j = s;
    while (j >= 1 && closed[j]) j--;
    if (j > 0) ans = min(ans, s - j);
    cout << ans << "\n";
  }
  return 0;
}
