#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, s, k, a[1000], c1 = 0, c2 = 0;
    cin >> n >> s >> k;
    map<long long, long long> vis;
    for (long long i = 0; i < k; i++) {
      cin >> a[i];
      vis[a[i]] = 1;
    }
    for (long long i = s; i <= n + 1; i++) {
      if (vis[i] == 1) {
        c1++;
      } else if (i == n + 1)
        c1 = 1e6;
      else
        break;
    }
    for (long long i = s; i >= 0; i--) {
      if (vis[i] == 1) {
        c2++;
      } else if (i == 0)
        c2 = 1e6;
      else
        break;
    }
    cout << min(c1, c2) << endl;
  }
}
