#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, s, k, mindist, flag = true;
    cin >> n >> s >> k;
    mindist = n + 1;
    int *A = new int[k + 2];
    A[k] = 0;
    A[k + 1] = n + 1;
    for (int i = 0; i < k; ++i) {
      cin >> A[i];
      if (A[i] == s) flag = false;
    }
    sort(A, A + k + 2);
    if (flag) {
      mindist = 0;
    } else {
      for (int i = 1; i < k + 1; ++i) {
        if (A[i] - 1 > A[i - 1]) mindist = min(mindist, abs(A[i] - 1 - s));
        if (A[i] + 1 < A[i + 1]) mindist = min(mindist, abs(A[i] + 1 - s));
      }
    }
    cout << mindist << endl;
  }
}
