#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, s, k;
    cin >> n >> s >> k;
    set<int> closed;
    for (int i = 0; i < k; i++) {
      int te;
      cin >> te;
      closed.insert(te);
    }
    int count = 0;
    for (int count = 0; count < 1001; count++) {
      if (find(closed.begin(), closed.end(), s + count) == closed.end() &&
          s + count <= n) {
        cout << count << '\n';
        break;
      }
      if (find(closed.begin(), closed.end(), s - count) == closed.end() &&
          s - count > 0) {
        cout << count << '\n';
        break;
      }
    }
  }
}
