#include <bits/stdc++.h>
using namespace std;
const int INF = 987654321;
const int MOD = 1000000007;
map<int, bool> booleanMap;
int main() {
  ios_base::sync_with_stdio(false);
  long long testCases;
  cin >> testCases;
  while (testCases--) {
    int n, s, k, x, i = 0;
    booleanMap.clear();
    cin >> n >> s >> k;
    while (k--) {
      cin >> x;
      booleanMap[x] = 1;
    }
    while (1) {
      if (booleanMap[max(s - i, 1)] == 0 || booleanMap[min(s + i, n)] == 0) {
        break;
      }
      i++;
    }
    cout << i << endl;
  }
  return 0;
}
