#include <bits/stdc++.h>
const int INF = 1000000009;
const int MAXN = 100008;
const int MOD = 1000000007;
const double PI = 3.14159265359;
const double EPS = 1e-6;
using namespace std;
int test, n, m, d, cnt, ans;
int a[1001];
int main() {
  cin >> test;
  while (test--) {
    int n, s, k;
    int ans = INF;
    cin >> n >> s >> k;
    for (int i = 0; i < k; i++) {
      cin >> a[i];
    }
    for (int i = s; i >= max(1, s - 1001); i--) {
      bool ok = true;
      for (int j = 0; j < k; j++) {
        if (i == a[j]) ok = false;
      }
      if (ok) ans = min(ans, s - i);
    }
    for (int i = s; i <= min(s + 1001, n); i++) {
      bool ok = true;
      for (int j = 0; j < k; j++) {
        if (i == a[j]) ok = false;
      }
      if (ok) ans = min(ans, i - s);
    }
    for (int i = 0; i < k; i++) a[i] = 0;
    cout << ans << '\n';
  }
  return 0;
};
