#include <bits/stdc++.h>
using namespace std;
int T, n, m, k, ans, a[10000];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%d", &n, &m, &k);
    ans = 2147483647;
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= k; i++) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + k);
    a[k + 1] = n + 1;
    a[0] = 0;
    for (int i = 1; i <= k + 1; i++) {
      if (m > a[i - 1] && m < a[i]) {
        ans = 0;
        break;
      } else if (a[i] - a[i - 1] > 1) {
        if (m >= a[i]) ans = min(ans, m - (a[i] - 1));
        if (m <= a[i - 1]) ans = min(ans, a[i - 1] + 1 - m);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
