#include <bits/stdc++.h>
using namespace std;
int t, n, s, k;
priority_queue<int, vector<int>, greater<int>> q;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> s >> k;
    while (!q.empty()) q.pop();
    for (int i = 0; i < k; ++i) {
      int tmp;
      cin >> tmp;
      q.push(abs(tmp - s));
    }
    int i = 0, flag = 1;
    while (!q.empty()) {
      if (q.top() != i) {
        flag = 0;
        cout << i << '\n';
        break;
      } else
        q.pop();
      if (i != 0 && s - i > 0 && s + i <= n) {
        if (q.empty() || q.top() != i) {
          flag = 0;
          cout << i << '\n';
          break;
        } else
          q.pop();
      }
      i++;
    }
    if (flag) cout << i << '\n';
  }
}
