#include <bits/stdc++.h>
using namespace std;
int getCurrPos(int l, int r, int arr[], int s) {
  if (l <= r) {
    int mid = l + (r - l) / 2;
    if (arr[mid] == s) return mid;
    if (arr[mid] > s) return getCurrPos(l, mid - 1, arr, s);
    return getCurrPos(mid + 1, r, arr, s);
  }
  return -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
  int t, n, s, k;
  cin >> t;
  while (t--) {
    cin >> n >> s >> k;
    int arr[k];
    bool sFoundInArr = false;
    for (int i = 0; i < k; i++) {
      cin >> arr[i];
      if (arr[i] == s) sFoundInArr = true;
    }
    if (!sFoundInArr)
      cout << 0 << endl;
    else {
      sort(arr, arr + k);
      int pos = getCurrPos(0, k - 1, arr, s);
      int minValBefore = INT_MAX;
      int minValAfter = INT_MAX;
      for (int i = pos; i >= 1; i--) {
        if (abs(arr[i] - arr[i - 1]) != 1) {
          minValBefore = arr[i] - 1;
          break;
        }
      }
      for (int i = pos; i < k - 1; i++) {
        if (abs(arr[i] - arr[i + 1]) != 1) {
          minValAfter = arr[i] + 1;
          break;
        }
      }
      if (minValBefore == INT_MAX) {
        if (arr[0] != 1) minValBefore = arr[0] - 1;
      }
      if (minValAfter == INT_MAX) {
        if (arr[k - 1] != n) minValAfter = arr[k - 1] + 1;
      }
      if (minValAfter != INT_MAX && minValBefore != INT_MAX) {
        cout << min(abs(minValBefore - s), abs(minValAfter - s)) << endl;
      } else if (minValAfter != INT_MAX) {
        cout << abs(minValAfter - s) << endl;
      } else {
        cout << abs(minValBefore - s) << endl;
      }
    }
  }
  return 0;
}
