#include <bits/stdc++.h>
using namespace std;
long long int fx[] = {1, 0, -1, 0, -1, -1, 1, 1};
long long int fy[] = {0, 1, 0, -1, -1, 1, -1, 1};
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, s, k, i, pos, ans1 = 1000000001, ans = 1000000001;
    cin >> n >> s >> k;
    vector<long long int> a(k);
    for (i = 0; i < k; i++) {
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    pos = lower_bound(a.begin(), a.end(), s) - a.begin();
    if (a[pos] != s)
      cout << 0 << "\n";
    else {
      for (i = pos; i < k - 1; i++) {
        if (a[i + 1] - a[i] > 1) {
          ans = ((a[i] + 1) - a[pos]);
          break;
        }
      }
      for (i = pos; i > 0; i--) {
        if (a[i] - a[i - 1] > 1) {
          ans1 = (a[pos] - (a[i] - 1));
          break;
        }
      }
      if (ans == 1000000001 && a[k - 1] != n) {
        ans = (a[k - 1] + 1) - s;
      }
      if (ans1 == 1000000001 && a[0] != 1) {
        ans1 = s - (a[0] - 1);
      }
      cout << min(ans1, ans) << "\n";
    }
  }
  return 0;
}
