#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, s, k;
    cin >> n >> s >> k;
    vector<long long int> v(k);
    for (int i = 0; i < k; i++) cin >> v[i];
    int flag = 0;
    for (int i = 0; i < k; i++) {
      if (s == v[i]) flag = 1;
    }
    if (flag == 0)
      cout << "0" << endl;
    else {
      int u = s + 1, l = s - 1;
      if (l == 0) l = 1;
      if (u == n + 1) u = n;
      for (long long int i = 1; i <= n; i++) {
        int flag1 = 0, flag2 = 0;
        for (long long int p = 0; p < k; p++) {
          if (u == v[p]) {
            flag1 = 1;
            break;
          }
        }
        for (long long int p = 0; p < k; p++) {
          if (l == v[p]) {
            flag2 = 1;
            break;
          }
        }
        if (flag1 == 0 || flag2 == 0) {
          cout << i << endl;
          break;
        } else {
          if (l == 1)
            l = 1;
          else
            l--;
          if (u == n)
            u = n;
          else
            u++;
        }
      }
    }
  }
}
