#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int checker = 1, changer = 0;
    long long n, s, k;
    cin >> n >> s >> k;
    long long a[k];
    for (long long i = 0; i < k; i++) {
      cin >> a[i];
    }
    while (checker == 1) {
      long long *p;
      p = find(a, a + k, s + changer);
      if (p == a + k && s + changer <= n) {
        cout << changer << endl;
        checker++;
        break;
      }
      p = find(a, a + k, s - changer);
      if (p == a + k && s - changer >= 1) {
        cout << changer << endl;
        checker++;
        break;
      }
      changer++;
    }
  }
}
