#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  int temp2 = 0;
  int test2 = 0;
  cin >> t;
  int n, s, k;
  for (int i = 1; i <= t; i++) {
    temp2 = 0;
    cin >> n;
    priority_queue<int> abc;
    cin >> s;
    priority_queue<int> xyz;
    cin >> k;
    long long mini = 0;
    abc.push(0);
    xyz.push((n + 1) * -1);
    for (int j = 1; j <= k; j++) {
      temp2++;
      int popo;
      cin >> popo;
      if (popo < s) {
        abc.push(popo);
      } else if (popo > s) {
        xyz.push(popo * -1);
      } else {
        mini = 100000000000;
      }
    }
    if (mini == 0) {
      test2++;
      cout << "0\n";
      continue;
    } else {
      long long now = 0, next = 0;
      while (!abc.empty()) {
        next = s - abc.top();
        abc.pop();
        if (next - now > 1) {
          mini = min(mini, now + 1);
          break;
        }
        now = next;
      }
      now = 0;
      while (!xyz.empty()) {
        temp2--;
        next = (xyz.top() * -1) - s;
        xyz.pop();
        if (next - now > 1) {
          mini = min(mini, now + 1);
          break;
          test2++;
        }
        now = next;
      }
    }
    cout << mini;
    cout << "\n";
  }
  return 0;
}
