#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t, n, i, j, m, k;
  cin >> t;
  while (t--) {
    cin >> n >> m >> k;
    map<long long, long long> mp;
    for (int i = 0; i < k; i++) {
      long long x;
      cin >> x;
      mp[x]++;
    }
    long long c = 0, r = INT_MAX;
    for (int i = m; i <= n; i++) {
      if (mp[i] == 0) {
        r = c;
        break;
      } else
        c++;
    }
    c = 0;
    for (int i = m; i >= 1; i--) {
      if (mp[i] == 0) {
        r = min(r, c);
        break;
      } else
        c++;
    }
    cout << r << endl;
  }
  return 0;
}
