#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, unsigned long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x;
    }
    y = y >> 1;
    x = x * x;
  }
  return res;
}
long long int powermod(long long int x, unsigned long long int y,
                       long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % p;
    }
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void solve() {
  long long int n, s, k;
  cin >> n >> s >> k;
  set<long long int> closed;
  long long int temp;
  for (long long int i = (long long int)(0); i < (long long int)(k); i++) {
    cin >> temp;
    closed.insert(temp);
  }
  long long int i = s;
  long long int j = s;
  while (true) {
    if (closed.find(i) == closed.end()) {
      cout << abs(s - i) << endl;
      return;
    }
    if (closed.find(j) == closed.end()) {
      cout << abs(s - j) << endl;
      return;
    }
    if (i < n) {
      i += 1;
    }
    if (j > 1) {
      j -= 1;
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
