#include <bits/stdc++.h>
using namespace std;
int t, s, k, n, a;
bool vis[2001];
int main() {
  scanf("%d", &t);
  while (t--) {
    memset(vis, 0, sizeof(vis));
    scanf("%d%d%d", &n, &s, &k);
    for (int i = 1; i <= k; i++) {
      scanf("%d", &a);
      if (abs(a - s) <= 1000) vis[1000 - s + a] = 1;
    }
    for (int i = 0; i <= 1000; i++) {
      if (i + s <= 1000) vis[1000 - s - i] = 1;
      if (abs(n + i + 1 - s) <= 1000) vis[1001 + n + i - s] = 1;
    }
    for (int i = 0; i <= 1000; i++)
      if (vis[1000 - i] == 0 || vis[1000 + i] == 0) {
        printf("%d\n", i);
        break;
      }
  }
  return 0;
}
