#include <bits/stdc++.h>
using namespace std;
const long long N = 3e3;
long long q, k;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> q;
  while (q--) {
    long long n, s, ans = INT_MAX;
    cin >> n >> s >> k;
    bool arr[6001];
    for (int i = 0; i < 4001; i++) arr[i] = 0;
    for (int i = 0, x; i < k; i++) {
      cin >> x;
      if (abs(x - s) > 2000) continue;
      arr[2000 + (x - s)] = 1;
    }
    for (int i = 0; i < 2000; i++) {
      if ((!arr[2000 - i] && s - i > 0) || (s + i <= n && !arr[2000 + i])) {
        cout << i << "\n";
        break;
      }
    }
  }
}
