#include <bits/stdc++.h>
using namespace std;
const long long MAX = 2e5 + 5;
const long long modu = 1e9 + 7;
const long long inf = 1e17;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  t = 1;
  cin >> t;
  while (t--) {
    long long n, s, k;
    cin >> n >> s >> k;
    long long c = 0;
    map<long long, long long> m;
    for (long long i = 0; i < k; i++) {
      long long x;
      cin >> x;
      m[x] = 1;
    }
    bool res1 = false, res2 = false;
    for (long long i = s; i <= n; i++) {
      if (c > 1002) {
        break;
      }
      if (m[i] == 0) {
        res1 = true;
        break;
      }
      c++;
    }
    long long c1 = 0;
    for (long long i = s; i > 0; i--) {
      if (c1 > 1002) {
        break;
      }
      if (m[i] == 0) {
        res2 = true;
        break;
      }
      c1++;
    }
    if (res1 && res2)
      cout << min(c1, c) << "\n";
    else if (res1)
      cout << c << "\n";
    else
      cout << c1 << "\n";
  }
}
