#include <bits/stdc++.h>
using namespace std;
long long a[100005];
map<long long, int> bk;
int main() {
  ios::sync_with_stdio(0);
  long long t;
  cin >> t;
  while (t--) {
    long long x, y, z, pos;
    cin >> x >> y >> z;
    bk.clear();
    for (int i = 1; i <= z; i++) cin >> a[i], bk[a[i]] = 1;
    sort(a + 1, a + 1 + z);
    if (a[pos = lower_bound(a + 1, a + 1 + z, y) - a] == y) {
      if (pos == z + 1) {
        cout << "0\n";
        continue;
      }
      long long cnt = 0;
      while (1) {
        cnt++;
        if (!bk[y + cnt] && y + cnt <= x) break;
        if (!bk[y - cnt] && y - cnt >= 1) break;
      }
      cout << cnt << "\n";
    } else
      cout << "0\n";
  }
}
