#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int mod = 1e9 + 7;
int p[100001];
int brr[100001];
int bit(int x) { return log2(x) + 1; }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, s1, k;
    cin >> n >> s1 >> k;
    set<int> s;
    int x;
    for (int i = 0; i < k; i++) {
      cin >> x;
      s.insert(x);
    }
    int i = 0;
    int f = 1;
    while (f == 1) {
      int a = s1 + i;
      int b = s1 - i;
      if (s1 + i <= n && s.find(a) == s.end()) {
        cout << i << endl;
        break;
      }
      if (s1 - i > 0 && s.find(b) == s.end()) {
        cout << i << endl;
        break;
      }
      i++;
    }
  }
}
