#include <bits/stdc++.h>
using namespace std;
set<int> f;
bool flag;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int all, curr, clos;
    cin >> all >> curr >> clos;
    f.clear();
    flag = false;
    for (int i = 0; i < clos; ++i) {
      int tmp;
      cin >> tmp;
      if (curr == tmp) flag = true;
      f.insert(tmp);
    }
    if (!flag)
      cout << '0' << endl;
    else {
      int ans = 2e9;
      for (int i = curr - 1, j = curr + 1; i >= 1 || j <= all; ++j, --i) {
        if (i >= 1) {
          if (f.count(i) == 0) {
            ans = min(ans, abs(i - curr));
            break;
          }
        }
        if (j <= all) {
          if (f.count(j) == 0) {
            ans = min(ans, abs(j - curr));
            break;
          }
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
