#include <bits/stdc++.h>
using namespace std;
const long long logN = 20;
const long long M = 1000000007;
const long long INF = 1e12;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, s, k;
    cin >> n >> s >> k;
    long long a[k];
    map<long long, long long> mp;
    for (long long i = 0; i < k; i++) {
      cin >> a[i];
      mp[a[i]]++;
    }
    for (long long i = 0; i < k + 1; i++) {
      if (s - i > 0 && mp[s - i] == 0) {
        cout << i;
        break;
      }
      if (s + i <= n && mp[i + s] == 0) {
        cout << i;
        break;
      }
    }
    cout << "\n";
  }
}
