#include <bits/stdc++.h>
using namespace std;
const long long N = 300010;
long long t, n, s, k, a[1010];
map<long long, bool> mp;
vector<long long> op;
int main() {
  scanf("%lld", &t);
  while (t--) {
    long long res = 1e18;
    op.clear();
    mp.clear();
    scanf("%lld", &n);
    scanf("%lld%lld", &s, &k);
    for (int i = 0; i < k; i++) {
      scanf("%lld", &a[i]);
      mp[a[i]] = 1;
    }
    if (mp[s] == 0) op.push_back(s);
    if (s - 1 > 0 && mp[s - 1] == 0) op.push_back(s - 1);
    if (s + 1 <= n && mp[s + 1] == 0) op.push_back(s + 1);
    for (int i = 0; i < k; i++) {
      if (a[i] - 1 > 0 && mp[a[i] - 1] == 0) op.push_back(a[i] - 1);
      if (a[i] + 1 <= n && mp[a[i] + 1] == 0) op.push_back(a[i] + 1);
    }
    for (long long val : op) {
      res = min(res, abs(val - s));
    }
    printf("%lld\n", res);
  }
  return 0;
}
