#include <bits/stdc++.h>
using namespace std;
int n, s, m;
int a[2000];
set<int> ss;
int find(int s) {
  for (int i = 0; i <= 1000; i++) {
    int k = s - i;
    if (k > 0 && ss.find(k) == ss.end()) return i;
    k = s + i;
    if (k <= n && ss.find(k) == ss.end()) return i;
  }
  return 1001;
}
int main() {
  int tt;
  scanf("%d", &tt);
  for (int t = 0; t < tt; t++) {
    scanf("%d%d%d", &n, &s, &m);
    ss.clear();
    for (int i = 0; i < m; i++) {
      scanf("%d", &a[i]);
      ss.insert(a[i]);
    }
    cout << find(s) << endl;
  }
}
