#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    unordered_map<int, int> umap;
    int m;
    cin >> m;
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int a;
      cin >> a;
      umap[a] = 1;
    }
    if (umap.find(m) == umap.end()) {
      cout << 0;
    } else {
      int u = m, d = m;
      while (d > 0) {
        if (umap.find(d) == umap.end()) break;
        d--;
      }
      while (u < n + 1) {
        if (umap.find(u) == umap.end()) break;
        u++;
      }
      if (d == 0)
        cout << u - m;
      else if (u == n + 1)
        cout << m - d;
      else
        cout << min(m - d, u - m);
    }
    cout << endl;
  }
  return 0;
}
