#include <bits/stdc++.h>
using namespace std;
int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, s, k, i, j, value, t;
  cin >> t;
  while (t--) {
    cin >> n >> s >> k;
    map<long long, long long> mp;
    long long flag = 0, first = 10000000000, second = 10000000000;
    for (i = 1; i <= k; i++) {
      cin >> value;
      mp[value] = 1;
    }
    for (i = s; i >= 1; i--) {
      if (mp[i] == 0) {
        first = i;
        break;
      }
    }
    for (i = s + 1; i <= n; i++) {
      if (mp[i] == 0) {
        second = i;
        break;
      }
    }
    long long check1, check2;
    check1 = abs(s - first);
    check2 = abs(s - second);
    cout << min(check1, check2) << "\n";
  }
  return 0;
}
