#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e4 + 10;
int T;
int n, s, k;
map<int, int> ma;
int main() {
  scanf("%d", &T);
  while (T--) {
    ma.clear();
    scanf("%d%d%d", &n, &s, &k);
    for (int i = 1; i <= k; i++) {
      int x;
      scanf("%d", &x);
      ma[x] = 1;
    }
    int t1 = s;
    while (ma[t1] && t1 <= n + 1) t1++;
    if (t1 == n + 1) t1 = INF;
    int t2 = s;
    while (ma[t2] && t2 >= 0) t2--;
    if (t2 == 0) t2 = INF;
    cout << min(abs(t1 - s), abs(t2 - s)) << endl;
  }
}
