 #pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
namespace in{
	char buf[1<<21],*p1=buf,*p2=buf;
	inline int getc(){
	    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
	}
	template <typename T>inline void read(T& t){
	    t=0;int f=0;char ch=getc();
	    while (!isdigit(ch)){
	        if(ch=='-')f = 1;
	        ch=getc();
	    }
	    while(isdigit(ch)){
   	    	t=t*10+ch-48;
   	    	ch = getc();
   		}
		if(f)t=-t;
	}
	template <typename T,typename... Args> inline void read(T& t, Args&... args){
	    read(t);read(args...);
	}
}
namespace out{
	char buffer[1<<21];
	int p1=-1;
	const int p2 = (1<<21)-1;
	inline void flush() {
		fwrite(buffer,1,p1+1,stdout),
		p1=-1;
	}
	inline void putc(const char &x) {
		if(p1==p2)flush();
		buffer[++p1]=x;
	}
	template <typename T>void write(T x) {
		static char buf[15];
		static int len=-1;
		if(x>=0){
			do{
    			buf[++len]=x%10+48,x/=10;
    		}while (x);
		}else{
    		putc('-');
			do {
    			buf[++len]=-(x%10)+48,x/=10;
			}while(x);
		}
		while (len>=0)
			putc(buf[len]),--len;
	}
}
using namespace std;
int t,n,x;
int num[3000];
int sumx,sumd,eq;
signed main(){
	in::read(t);
	while(t--){
		sumx=sumd=eq=0;
		in::read(n,x);
		for(int i=1;i<=n;i++){
			in::read(num[i]);
			if(num[i]<x)sumx+=x-num[i];
			if(num[i]>x)sumd+=num[i]-x;
			if(num[i]==x)eq++;
		}
		if(sumx==0&&sumd==0)puts("0");
		else if(sumx==0||sumd==0)puts("1");
		else if(sumx==sumd)puts("1");
		else if(eq)puts("1");
		else puts("2");
	}
	out::flush();
	return 0;
}


#include<bits/stdc++.h>
namespace in{
	char buf[1<<21],*p1=buf,*p2=buf;
	inline int getc(){
	    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
	}
	template <typename T>inline void read(T& t){
	    t=0;int f=0;char ch=getc();
	    while (!isdigit(ch)){
	        if(ch=='-')f = 1;
	        ch=getc();
	    }
	    while(isdigit(ch)){
   	    	t=t*10+ch-48;
   	    	ch = getc();
   		}
		if(f)t=-t;
	}
	template <typename T,typename... Args> inline void read(T& t, Args&... args){
	    read(t);read(args...);
	}
}
using namespace std;
#define int long long
int t,n,x;
int num;
int sumx,sumd,eq;
signed main(){
	in::read(t);
	while(t--){
		sumx=sumd=eq=0;
		in::read(n,x);
		for(int i=1;i<=n;i++){
			in::read(num);
			if(num<x)sumx+=x-num;
			if(num>x)sumd+=num-x;
			if(num==x)eq++;
		}
		if(eq==n)puts("0");
		else if(eq)puts("1");
		else if(sumx==sumd)puts("1");
		else puts("2");
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 1004;
const int INF = 0x3f3f3f3f;

int a[MAXN];
bool vis[MAXN];

int main() {
    int T; scanf("%d", &T);
    while(T--) {
        memset(vis, 0, sizeof(vis));
        int n, x;
        ll sum = 0;
        scanf("%d%d", &n, &x);
        for(int i = 0; i < n; ++i)
            scanf("%d", &a[i]);
        int tot = 0;
        for(int i = 0; i < n; ++i) {
            if(a[i] == x) {
                ++tot; vis[i] = 1;
            }
        }
        if(tot == n)
            puts("0");
        else if(tot == n - 1)
            puts("1");
        else {
            for(int i = 0; i < n; ++i) {
                if(!vis[i])
                    sum += a[i];
            }
            if(x == 0 && sum == 0) puts("1");
            else if(x != 0 && sum % x == 0) puts("1");
            else puts("2");
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 1004;
const int INF = 0x3f3f3f3f;

int a[MAXN];
bool vis[MAXN];

int main() {
    int T; scanf("%d", &T);
    while(T--) {
        int n, x;
        ll sum = 0;
        scanf("%d%d", &n, &x);
        for(int i = 0; i < n; ++i)
            scanf("%d", &a[i]);
        int tot = 0;
        for(int i = 0; i < n; ++i) {
            if(a[i] == x) {
                ++tot; vis[i] = 1;
            }
        }
        if(tot >= n - 1)
            puts("0");
        else {
            for(int i = 0; i < n; ++i) {
                if(!vis[i])
                    sum += a[i];
            }
            if(sum % x == 0) puts("1");
            else puts("2");
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 1004;
const int INF = 0x3f3f3f3f;

int a[MAXN];

int main() {
    int T; scanf("%d", &T);
    while(T--) {
        int n, x;
        ll sum = 0;
        scanf("%d%d", &n, &x);
        for(int i = 0; i < n; ++i)
            scanf("%d", &a[i]);
        int tot = 0;
        for(int i = 0; i < n; ++i)
            if(a[i] == x) ++tot;
        if(tot == n)
            puts("0");
        else if(tot)
            puts("1");
        else {
            for(int i = 0; i < n; ++i)
                sum += a[i] - x;
            puts(sum ? "2" : "1");
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 1004;
const int INF = 0x3f3f3f3f;

int a[MAXN];

int main() {
    int T; scanf("%d", &T);
    while(T--) {
        int n, x;
        ll sum = 0;
        scanf("%d%d", &n, &x);
        for(int i = 0; i < n; ++i)
            scanf("%d", &a[i]);
        int tot = 0;
        for(int i = 0; i < n; ++i) {
            if(a[i] == x) {
                ++tot;
            }
        }
        if(tot == n)
            puts("0");
        else if(tot)
            puts("1");
        else {
            for(int i = 0; i < n; ++i)
                sum += a[i];
            if(x == 0) {
                if(sum == 0) puts("1");
                else puts("2");
            }
            else {
                if(sum == 0) puts("2");
                else if(sum % x) puts("2");
                else puts("1");
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 1004;
const int INF = 0x3f3f3f3f;

int a[MAXN];
bool vis[MAXN];

int main() {
    int T; scanf("%d", &T);
    while(T--) {
        int n, x;
        ll sum = 0;
        scanf("%d%d", &n, &x);
        for(int i = 0; i < n; ++i)
            scanf("%d", &a[i]);
        int tot = 0;
        for(int i = 0; i < n; ++i) {
            if(a[i] == x) {
                ++tot; vis[i] = 1;
            }
        }
        if(tot == n)
            puts("0");
        else if(tot)
            puts("1");
        else {
            for(int i = 0; i < n; ++i)
                if(!vis[i]) sum += a[i];
            if(x == 0) {
                if(sum == 0) puts("1");
                else puts("2");
            }
            else {
                if(sum % x) puts("2");
                else puts("1");
            }
        }
        for(int i = 0; i < n; ++i)vis[i] = 0;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 1004;
const int INF = 0x3f3f3f3f;

int a[MAXN];
bool vis[MAXN];

int main() {
    int T; scanf("%d", &T);
    while(T--) {
        memset(vis, 0, sizeof(vis));
        int n, x;
        ll sum = 0;
        scanf("%d%d", &n, &x);
        for(int i = 0; i < n; ++i)
            scanf("%d", &a[i]);
        int tot = 0;
        for(int i = 0; i < n; ++i) {
            if(a[i] == x) {
                ++tot; vis[i] = 1;
            }
        }
        if(tot >= n - 1)
            puts("0");
        else {
            for(int i = 0; i < n; ++i) {
                if(!vis[i])
                    sum += a[i];
            }
            if(x == 0 && sum == 0) puts("1");
            else if(x != 0 && sum % x == 0) puts("1");
            else puts("2");
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 1004;
const int INF = 0x3f3f3f3f;

int a[MAXN];

int main() {
    int T; scanf("%d", &T);
    while(T--) {
        int n, x;
        ll sum = 0;
        scanf("%d%d", &n, &x);
        for(int i = 0; i < n; ++i)
            scanf("%d", &a[i]);
        int tot = 0;
        for(int i = 0; i < n; ++i)
            if(a[i] == x) ++tot;
        if(tot == n)
            puts("0");
        else if(tot)
            puts("1");
        else {
            if(n == 1) {
                puts("1"); continue;
            }
            for(int i = 0; i < n; ++i)
                sum += a[i];
            if(sum && x) {
                printf("%d\n", sum % x ? 2 : 1);
            }
            else {
                printf("%d\n", sum || x ? 2 : 1);
            }
        }
    }
    return 0;
}


#define IO_NAME ""
#include "cstdio"

#define ll long long
#define re register
#define il inline
#define tt template <class T>
#define gc getchar
#define pc putchar

tt il void read(T &x)
{
  re bool f = false;
  re char c = gc();
  while ((c < '0' || c > '9') && c != '-')
    c = gc();
  if (c == '-')
    f = true, c = gc();
  x = 0;
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = gc();
  f && (x = -x);
}

tt void print(T x)
{
  (x < 0) && (pc('-'), x = -x);
  if (x >= 10)
    print(x / 10);
  pc(x % 10 + '0');
}

tt il void prisp(T x)
{
  print(x);
  pc(' ');
}

tt il void priln(T x)
{
  print(x);
  pc('\n');
}

tt il T max(T a, T b)
{
  if (a < b)
    return b;
  return a;
}

tt il T min(T a, T b)
{
  if (a < b)
    return a;
  return b;
}

int t;
int n, x;
int s, a[1005];

int main()
{
  read(t);
  while (t--)
  {
    read(n);
    read(x);
    bool f1 = true, f2 = false;
    for (re int i = 1; i <= n; ++i)
    {
      read(a[i]);
      s += a[i];
      if (a[i] != x) f1 = false;
      else f2 = true;
    }
    if (f1)
    {
      priln(0);
    }
    else if (f2 || s == n)
    {
      priln(1);
    }
    else
    {
      priln(2);
    }
  }
}


#define IO_NAME ""
#include "cstdio"

#define ll long long
#define re register
#define il inline
#define tt template <class T>
#define gc getchar
#define pc putchar

tt il void read(T &x)
{
  re bool f = false;
  re char c = gc();
  while ((c < '0' || c > '9') && c != '-')
    c = gc();
  if (c == '-')
    f = true, c = gc();
  x = 0;
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = gc();
  f && (x = -x);
}

tt void print(T x)
{
  (x < 0) && (pc('-'), x = -x);
  if (x >= 10)
    print(x / 10);
  pc(x % 10 + '0');
}

tt il void prisp(T x)
{
  print(x);
  pc(' ');
}

tt il void priln(T x)
{
  print(x);
  pc('\n');
}

tt il T max(T a, T b)
{
  if (a < b)
    return b;
  return a;
}

tt il T min(T a, T b)
{
  if (a < b)
    return a;
  return b;
}

int t;
int n, x;
int s, a[1005];

int main()
{
  read(t);
  while (t--)
  {
    read(n);
    read(x);
    bool f = true;
    for (re int i = 1; i <= n; ++i)
    {
      read(a[i]);
      s += a[i];
      if (a[i] != x) f = false;
    }
    if (f)
    {
      priln(0);
    }
    else if (s == x * n)
    {
      priln(1);
    }
    else
    {
      priln(2);
    }
  }
}


#define IO_NAME ""
#include "cstdio"

#define ll long long
#define re register
#define il inline
#define tt template <class T>
#define gc getchar
#define pc putchar

tt il void read(T &x)
{
  re bool f = false;
  re char c = gc();
  while ((c < '0' || c > '9') && c != '-')
    c = gc();
  if (c == '-')
    f = true, c = gc();
  x = 0;
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = gc();
  f && (x = -x);
}

tt void print(T x)
{
  (x < 0) && (pc('-'), x = -x);
  if (x >= 10)
    print(x / 10);
  pc(x % 10 + '0');
}

tt il void prisp(T x)
{
  print(x);
  pc(' ');
}

tt il void priln(T x)
{
  print(x);
  pc('\n');
}

tt il T max(T a, T b)
{
  if (a < b)
    return b;
  return a;
}

tt il T min(T a, T b)
{
  if (a < b)
    return a;
  return b;
}

int t;
int n, x;
int s, a[1005];

int main()
{
  read(t);
  while (t--)
  {
    read(n);
    read(x);
    bool f1 = true, f2 = false;
    for (re int i = 1; i <= n; ++i)
    {
      read(a[i]);
      s += a[i];
      if (a[i] != x) f1 = false;
      else f2 = true;
    }
    if (f1)
    {
      priln(0);
    }
    else if (f2 || s == x * n)
    {
      priln(1);
    }
    else
    {
      priln(2);
    }
  }
}


#define IO_NAME ""
#include "cstdio"

#define ll long long
#define re register
#define il inline
#define tt template <class T>
#define gc getchar
#define pc putchar

tt il void read(T &x)
{
  re bool f = false;
  re char c = gc();
  while ((c < '0' || c > '9') && c != '-')
    c = gc();
  if (c == '-')
    f = true, c = gc();
  x = 0;
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = gc();
  f && (x = -x);
}

tt void print(T x)
{
  (x < 0) && (pc('-'), x = -x);
  if (x >= 10)
    print(x / 10);
  pc(x % 10 + '0');
}

tt il void prisp(T x)
{
  print(x);
  pc(' ');
}

tt il void priln(T x)
{
  print(x);
  pc('\n');
}

tt il T max(T a, T b)
{
  if (a < b)
    return b;
  return a;
}

tt il T min(T a, T b)
{
  if (a < b)
    return a;
  return b;
}

int t;
int n, x;
int a[1005];

int main()
{
  read(t);
  while (t--)
  {
    read(n);
    read(x);
    bool f1 = true, f2 = false;
    int s = 0;
    for (re int i = 1; i <= n; ++i)
    {
      read(a[i]);
      s += a[i];
      if (a[i] != x) f1 = false;
      else f2 = true;
    }
    if (f1)
    {
      priln(0);
    }
    else if (f2 || s == x * n)
    {
      priln(1);
    }
    else
    {
      priln(2);
    }
  }
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define vb vector<bool>
#define inf 1000000100
#define infll 1LL << 62
#define PI 3.141592653589793238462643383279502884197169
#define MOD 1000000007

ll gcd(ll a, ll b)
{
    if(b == 0)
    {
        return a;
    }
    return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a/g * b; //prevent overflow
}

ll ncr(ll n, ll r)
{
    if(n-r < r)
    {
        r = n-r;
    }

    ll ret = 1;

    for(ll i = 1; i <= r; ++i)
    {
        ret *= (n-r+i);
        ret /= i;
    }
    return ret;
}
////////////////////////  END OF TEMPLATE ////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n, x;
        cin >> n >> x;
        vi data(n);
        int sum = 0, ans = 2;
        bool ax = 1, kj = 0;
        for(int i = 0; i < n; ++i)
        {
            cin >> data[i];
            sum += data[i];
            if(data[i] != x)
            {
                ax = 0;
            }
            else
            {
                kj = 1;
            }
        }
        if(sum % n == 0 && kj)
        {
            ans = min(ans, 1);
        }
        if(kj && sum % (n-1) == x)
        {
            ans = min(ans, 1);
        }
        if(sum % n == 0 && sum == n*x)
        {
            if(ax)
            {
                ans = min(ans, 0);
            }
            else
            {
                ans = min(ans, 1);
            }
        }
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define vb vector<bool>
#define inf 1000000100
#define infll 1LL << 62
#define PI 3.141592653589793238462643383279502884197169
#define MOD 1000000007

ll gcd(ll a, ll b)
{
    if(b == 0)
    {
        return a;
    }
    return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a/g * b; //prevent overflow
}

ll ncr(ll n, ll r)
{
    if(n-r < r)
    {
        r = n-r;
    }

    ll ret = 1;

    for(ll i = 1; i <= r; ++i)
    {
        ret *= (n-r+i);
        ret /= i;
    }
    return ret;
}
////////////////////////  END OF TEMPLATE ////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n, x;
        cin >> n >> x;
        vi data(n);
        int sum = 0, ans = 2;
        bool ax = 1, kj = 0;
        for(int i = 0; i < n; ++i)
        {
            cin >> data[i];
            sum += data[i];
            if(data[i] != x)
            {
                ax = 0;
            }
            else
            {
                kj = 1;
            }
        }
        if(sum % n == 0 && kj)
        {
            ans = min(ans, 1);
        }
        if(kj)
        {
            for(int i = 2; i <= n-1; ++i)
            {
                if((sum%i)%x == 0 && (sum % i) / x == n-i)
                {
                   ans = min(ans, 1);
                }
            }
        }
        if(sum % n == 0 && sum == n*x)
        {
            if(ax)
            {
                ans = min(ans, 0);
            }
            else
            {
                ans = min(ans, 1);
            }
        }
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define vb vector<bool>
#define inf 1000000100
#define infll 1LL << 62
#define PI 3.141592653589793238462643383279502884197169
#define MOD 1000000007

ll gcd(ll a, ll b)
{
    if(b == 0)
    {
        return a;
    }
    return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a/g * b; //prevent overflow
}

ll ncr(ll n, ll r)
{
    if(n-r < r)
    {
        r = n-r;
    }

    ll ret = 1;

    for(ll i = 1; i <= r; ++i)
    {
        ret *= (n-r+i);
        ret /= i;
    }
    return ret;
}
////////////////////////  END OF TEMPLATE ////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n, x;
        cin >> n >> x;
        vi data(n);
        int sum = 0, ans = 2;
        bool ax = 1, kj = 0;
        for(int i = 0; i < n; ++i)
        {
            cin >> data[i];
            sum += data[i];
            if(data[i] != x)
            {
                ax = 0;
            }
            else
            {
                kj = 1;
            }
        }
        if(sum % n == 0 && kj)
        {
            ans = min(ans, 1);
        }
        if(kj)
        {
            for(int i = 1; i <= n-1; ++i)
            {
                if(((sum%i)%x == 0) && ((sum % i) / x == n-i))
                {
                   ans = min(ans, 1);
                }
            }
        }
        if(sum % n == 0 && sum == n*x)
        {
            if(ax)
            {
                ans = min(ans, 0);
            }
            else
            {
                ans = min(ans, 1);
            }
        }
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define vb vector<bool>
#define inf 1000000100
#define infll 1LL << 62
#define PI 3.141592653589793238462643383279502884197169
#define MOD 1000000007

ll gcd(ll a, ll b)
{
    if(b == 0)
    {
        return a;
    }
    return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a/g * b; //prevent overflow
}

ll ncr(ll n, ll r)
{
    if(n-r < r)
    {
        r = n-r;
    }

    ll ret = 1;

    for(ll i = 1; i <= r; ++i)
    {
        ret *= (n-r+i);
        ret /= i;
    }
    return ret;
}
////////////////////////  END OF TEMPLATE ////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n, x;
        cin >> n >> x;
        vi data(n);
        int sum = 0, ans = 0;
        bool sm = 1;
        for(int i = 0; i < n; ++i)
        {
            cin >> data[i];
            sum += data[i];
            if(data[i] != x)
            {
                sm = 0;
            }
        }
        if(sum % n == 0 && sum == n*x)
        {
            ans--;
        }
        if(sm)
        {
            ans--;
        }
        cout << ans+2 << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define vb vector<bool>
#define inf 1000000100
#define infll 1LL << 62
#define PI 3.141592653589793238462643383279502884197169
#define MOD 1000000007

ll gcd(ll a, ll b)
{
    if(b == 0)
    {
        return a;
    }
    return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a/g * b; //prevent overflow
}

ll ncr(ll n, ll r)
{
    if(n-r < r)
    {
        r = n-r;
    }

    ll ret = 1;

    for(ll i = 1; i <= r; ++i)
    {
        ret *= (n-r+i);
        ret /= i;
    }
    return ret;
}
////////////////////////  END OF TEMPLATE ////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n, x;
        cin >> n >> x;
        vi data(n);
        int sum = 0, ans = 2;
        bool ax = 1, kj = 0;
        for(int i = 0; i < n; ++i)
        {
            cin >> data[i];
            sum += data[i];
            if(data[i] != x)
            {
                ax = 0;
            }
            else
            {
                kj = 1;
            }
        }
        if(sum % n == 0 && kj)
        {
            ans = 1;
        }
        if(sum % n == 0 && sum == n*x)
        {
            if(ax)
            {
                ans = 0;
            }
            else
            {
                ans = 1;
            }
        }
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define vb vector<bool>
#define inf 1000000100
#define infll 1LL << 62
#define PI 3.141592653589793238462643383279502884197169
#define MOD 1000000007

ll gcd(ll a, ll b)
{
    if(b == 0)
    {
        return a;
    }
    return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a/g * b; //prevent overflow
}

ll ncr(ll n, ll r)
{
    if(n-r < r)
    {
        r = n-r;
    }

    ll ret = 1;

    for(ll i = 1; i <= r; ++i)
    {
        ret *= (n-r+i);
        ret /= i;
    }
    return ret;
}
////////////////////////  END OF TEMPLATE ////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n, x;
        cin >> n >> x;
        vi data(n);
        int sum = 0, ans = 2;
        bool ax = 1, kj = 0;
        for(int i = 0; i < n; ++i)
        {
            cin >> data[i];
            sum += data[i];
            if(data[i] != x)
            {
                ax = 0;
            }
            else
            {
                kj = 1;
            }
        }
        if(sum % n == 0 && kj)
        {
            ans = min(ans, 1);
        }
        if(kj)
        {
            for(int i = 2; i <= n-1; ++i)
            {
                if((sum % i) % x == 0)
                {
                   ans = min(ans, 1);
                }
            }
        }
        if(sum % n == 0 && sum == n*x)
        {
            if(ax)
            {
                ans = min(ans, 0);
            }
            else
            {
                ans = min(ans, 1);
            }
        }
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define vb vector<bool>
#define inf 1000000100
#define infll 1LL << 62
#define PI 3.141592653589793238462643383279502884197169
#define MOD 1000000007

ll gcd(ll a, ll b)
{
    if(b == 0)
    {
        return a;
    }
    return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a/g * b; //prevent overflow
}

ll ncr(ll n, ll r)
{
    if(n-r < r)
    {
        r = n-r;
    }

    ll ret = 1;

    for(ll i = 1; i <= r; ++i)
    {
        ret *= (n-r+i);
        ret /= i;
    }
    return ret;
}
////////////////////////  END OF TEMPLATE ////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n, x;
        cin >> n >> x;
        vi data(n);
        int sum = 0, ans = 2;
        bool ax = 1, kj = 0;
        for(int i = 0; i < n; ++i)
        {
            cin >> data[i];
            sum += data[i];
            if(data[i] != x)
            {
                ax = 0;
            }
            else
            {
                kj = 1;
            }
        }
        if(kj)
        {
            ans = min(ans, 1);

        }
        if(sum % n == 0 && sum == n*x)
        {
            if(ax)
            {
                ans = min(ans, 0);
            }
            else
            {
                ans = min(ans, 1);
            }
        }
        cout << ans << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
main(){
	int tc;
	cin>>tc;
	while(tc--){
		int  n;
		int x;
		cin>>n>>x;

		int arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}

		int check=0;
		for(int i=0;i<n;i++){
			if(arr[i]==x) continue;
			check=1;
			break;
		}
		if(check==0){
			cout<<"0"<<endl;
			continue;
		}
		long long sum=0;
		for(int i=0;i<n;i++){
			sum+=arr[i]-x;
		}
		if(sum==0){
			cout<<"1"<<endl;
		}else cout<<"2"<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
main(){
	int tc;
	cin>>tc;
	while(tc--){
		int  n;
		int x;
		cin>>n>>x;

		int arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}

		int check=0;
		int sokhac=0;
		for(int i=0;i<n;i++){
			if(arr[i]==x) continue;
			sokhac++;
			check=1;
		}
		if(check==0){
			cout<<"0"<<endl;
			continue;
		}

		long long sum=0;
		for(int i=0;i<n;i++){
			sum+=arr[i]-x;
		}
		if(sum==0){
			cout<<"1"<<endl;
		}else {
			if(sokhac==1){
			cout<<"1"<<endl;
			continue;}

			else {
				cout<<"2"<<endl;
			}

		}

		}
	}


#include<bits/stdc++.h>
using namespace std;
main(){
	int tc;
	cin>>tc;
	while(tc--){
		int  n;
		int x;
		cin>>n>>x;

		int arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}

		int check=0;
		for(int i=0;i<n;i++){
			if(arr[i]==x) continue;
			check=1;
			break;
		}
		if(check==0){
			cout<<"0"<<endl;
			continue;
		}
		long long sum=0;
		for(int i=0;i<n;i++){
			sum+=arr[i]-x;
		}
		if(sum==0){
			cout<<"1"<<endl;
		}else cout<<"2";
	}

}


#include<bits/stdc++.h>
using namespace std;
main(){
	int tc;
	cin>>tc;
	while(tc--){
		int  n;
		int x;
		cin>>n>>x;

		int arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}

		int check=0;
		int sokhac=0;
		for(int i=0;i<n;i++){
			if(arr[i]==x) continue;
			sokhac++;
			check=1;
		}
		if(check==0){
			cout<<"0"<<endl;
			continue;
		}

		long long sum=0;
		for(int i=0;i<n;i++){
			sum+=arr[i]-x;
		}
		if(sum==0){
			cout<<"1"<<endl;
		}else {
			if(sokhac==1){
				cout<<"1"<<endl;

			}
		else	if(sokhac==n){
				cout<<"2"<<endl;
			}

			else {
				cout<<"1"<<endl;
			}

		}

		}
	}


#include<bits/stdc++.h>
using namespace std;
main(){
	int tc;
	cin>>tc;
	while(tc--){
		int  n;
		int x;
		cin>>n>>x;

		int arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}

		int check=0;
		for(int i=0;i<n;i++){
			if(arr[i]==x) continue;
			check=1;
			break;
		}
		if(check==0){
			cout<<"0"<<endl;
		}
		long long sum=0;
		for(int i=0;i<n;i++){
			sum+=arr[i]-x;
		}
		if(sum==0){
			cout<<"1"<<endl;
		}else cout<<"2";
	}

}


#include<bits/stdc++.h>
using namespace std;
main(){
	int tc;
	cin>>tc;
	while(tc--){
		int  n;
		int x;
		cin>>n>>x;

		int arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}

		int check=0;
		int sokhac=0;
		for(int i=0;i<n;i++){
			if(arr[i]==x) continue;
			sokhac++;
			check=1;
		}
		if(check==0){
			cout<<"0"<<endl;
			continue;
		}
		if(sokhac==1){
			cout<<"1"<<endl;
			continue;

		}
		long long sum=0;
		for(int i=0;i<n;i++){
			sum+=arr[i]-x;
		}
		if(sum==0){
			cout<<"1"<<endl;
		}else cout<<"2"<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+9;
int a[maxn];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,x;
		scanf("%d%d",&n,&x);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		bool flag=true,flag1=false;
		int sum=0;
		for(int i=1;i<=n;i++){
			sum+=a[i];
			if(a[i]!=x) flag=false;
			if(a[i]==x) flag1=true;
		}
		if(flag) printf("0\n");
		else if(flag1&&sum%n==0)printf("1\n");
		else printf("2\n");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+9;
int a[maxn];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,x;
		scanf("%d%d",&n,&x);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		bool flag=false;
		int sum=0,cnt=0;
		for(int i=1;i<=n;i++){
			sum+=a[i];
			if(a[i]==x) cnt++;
		}
		if(cnt==n) printf("0\n");
		else if(cnt||(sum==x*n))printf("1\n");
		else printf("2\n");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+9;
int a[maxn];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,x;
		scanf("%d%d",&n,&x);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		bool flag=true;
		int sum=0;
		for(int i=1;i<=n;i++){
			sum+=a[i];
			if(a[i]!=x) flag=false;
		}
		bool flag1=false;
		for(int i=1;i<=10000;i++){
			if(sum==x*i){
				flag1=true;
				break;
			}
		}
		if(flag) printf("0\n");
		else if(flag1)printf("1\n");
		else printf("2\n");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+9;
int a[maxn];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,x;
		scanf("%d%d",&n,&x);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		bool flag=true;
		int sum=0;
		for(int i=1;i<=n;i++){
			sum+=a[i];
			if(a[i]!=x) flag=false;
		}
		bool flag1=false;
		for(int i=-4000;i<=4000;i++){
			if(sum==x*i){
				flag1=true;
				break;
			}
		}
		if(flag) printf("0\n");
		else if(flag1)printf("1\n");
		else printf("2\n");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+9;
int a[maxn];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,x;
		scanf("%d%d",&n,&x);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		bool flag=false;
		int sum=0,cnt=0;
		for(int i=1;i<=n;i++){
			sum+=a[i];
			if(a[i]==x) cnt++;
		}
		int sum1=sum-cnt*x;
		for(int i=0;i<=cnt;i++){
			if(cnt==n) break;
			if((sum1-i*x)%(n-i)==0){
				flag=true;
				break;
			}
		}
		if(cnt==n) printf("0\n");
		else if(flag)printf("1\n");
		else printf("2\n");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+9;
int a[maxn];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,x;
		scanf("%d%d",&n,&x);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		bool flag=false;
		int sum=0,cnt=0;
		for(int i=1;i<=n;i++){
			sum+=a[i];
			if(a[i]==x) cnt++;
		}
		for(int i=0;i<=cnt;i++){
			if(cnt==n) break;
			if((sum-i*x)%(n-i)==0){
				flag=true;
				break;
			}
		}
		if(cnt==n) printf("0\n");
		else if(flag)printf("1\n");
		else printf("2\n");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+9;
int a[maxn];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,x;
		scanf("%d%d",&n,&x);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		bool flag=false;
		int sum=0;
		for(int i=1;i<=n;i++){
			sum+=a[i];
			if(a[i]==x) flag=true;
		}
		bool flag1=false;
		for(int i=1;i<=10000;i++){
			if(sum==x*i){
				flag1=true;
				break;
			}
		}
		if(flag) printf("0\n");
		else if(flag1)printf("1\n");
		else printf("2\n");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+9;
int a[maxn];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,x;
		scanf("%d%d",&n,&x);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		bool flag=false;
		int sum=0;
		for(int i=1;i<=n;i++){
			sum+=a[i];
			if(a[i]==x) flag=true;
		}
		if(flag) printf("0\n");
		else if(sum%x==0)printf("1\n");
		else printf("2\n");
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int checkCase(int n, int x, vector<int> a){

     int count = 0;
     int diffSum = 0;

     for(int j=0; j<n; j++){
          if(a[j] == x){
               count++;
               diffSum+=(x - a[j]);
          }
          diffSum+=(x - a[j]);
     }

     if(diffSum != 0){
          return 2;
     } else {
          if(count == n){
               return 0;
          } else if(count != n && diffSum == 0){
               return 1;
          }
     }

}

int main(){

     int t; cin >> t;

     for(int i=0; i<t; i++){

        int n, x; cin >> n >> x;

        vector<int> as;

        for(int j=0; j<n; j++){
             int a; cin >> a;
             as.push_back(a);
        }

        cout << checkCase(n, x, as) << "\n";
     }

}


#include <bits/stdc++.h>

using namespace std;

int main(){

     int t; cin >> t;

     for(int i=0; i<t; i++){
          int n, x; cin >> n >> x;
          vector<int> v;
          for (int j=0; j<n; j++){
               int a; cin >> a;
               v.push_back(a);
          }

          int count = 0;
          int diffSum = 0;

          for (int j=0; j<n; j++){
               if(v[j] == x){
                    count++;
               }
               diffSum+=(v[j]-x);
          }

          if(count == n){
               cout << 0 << "\n";
          } else if(diffSum == 0 && count!= n){
               cout << 1 << "\n";
          } else {
               cout << 2 << "\n";
          }

     }

}


#include <bits/stdc++.h>

using namespace std;

int main(){

     int t; cin >> t;

     for(int i=0; i<t; i++){
          int n, x; cin >> n >> x;
          vector<int> v;
          for (int j=0; j<n; j++){
               int a; cin >> a;
               v.push_back(a);
          }

          int count = 0;
          int diffSum = 0;

          for (int j=0; j<n; j++){
               if(v[i] == x){
                    count++;
               }
               diffSum+=(x - v[j]);
          }
          if(count == n){
               cout << 0;
               break;
          } else if(diffSum == 0 && count!= n){
               cout << 1;
               break;
          } else {
               cout << 2;
               break;
          }

     }

}


#include <bits/stdc++.h>

using namespace std;
using pb = push_back;

int main(){

     int t; cin >> t;

     for(int i=0; i<t; i++){
          int n, x; cin >> n >> x;
          vector<int> v;
          for (int j=0; j<n; j++){
               int a; cin >> a;
               v.pb(a);
          }

          int count = 0;
          int diffSum = 0;

          for (int j=0; j<n; j++){
               if(v[i] == x){
                    count++;
               }
               diffSum+=(x - v[j]);
          }
          if(count == n){
               cout << 0;
               break;
          } else if(diffSum == 0 && count!= n){
               cout << 1;
               break;
          } else {
               cout << 2;
               break;
          }

     }

}


#include <bits/stdc++.h>

using namespace std;

int checkCase(int n, int x, vector<int> a){

     int count = 0;
     int diffSum = 0;

     for(int j=0; j<n; j++){
          if(a[j] == x){
               count++;
               diffSum+=(x - a[j]);
          }
          diffSum+=(x - a[j]);
     }

     if(diffSum != 0){
          cout << 2 << "\n";
     } else {
          if(count == n){
               cout << 0 << "\n";
          } else if(count != n && diffSum == 0){
               cout << 1 << "\n";
          }
     }

}

int main(){

     int t; cin >> t;

     for(int i=0; i<t; i++){

        int n, x; cin >> n >> x;

        vector<int> as;

        for(int j=0; j<n; j++){
             int a; cin >> a;
             as.push_back(a);
        }

        checkCase(n, x, as);

     }

}


#include <bits/stdc++.h>

using namespace std;

int checkCase(int n, int x, vector<int> a){

     int count = 0;
     int diffSum = 0;

     for(int j=0; j<n; j++){
          if(a[j] == x){
               count++;
               diffSum+=(x - a[i]);
          }
          diffSum+=(x - a[i]);
     }

     if(diffSum != 0){
          cout << 2 << "\n";
     } else {
          if(count == n){
               cout << 0 << "\n";
          } else if(count != n && diffSum == 0){
               cout << 1 << "\n";
          }
     }

}

int main(){

     int t; cin >> t;

     for(int i=0; i<t; i++){

        int n, x; cin >> n >> x;

        vector<int> as;

        for(int j=0; j<n; j++){
             int a; cin >> a;
             as.push_back(a);
        }

        checkCase(n, x, as);

     }

}


#include <bits/stdc++.h>

using namespace std;

int main(){

     int t; cin >> t;

     for(int i=0; i<t; i++){
          int n, x; cin >> n >> x;
          vector<int> v;
          for (int j=0; j<n; j++){
               int a; cin >> a;
               v.push_back(a);
          }

          int count = 0;
          int diffSum = 0;

          for (int j=0; j<n; j++){
               if(v[i] == x){
                    count++;
               }
               diffSum+=(x - v[j]);
          }
          if(count == n){
               cout << 0 << "\n";
          } else if(diffSum == 0 && count!= n){
               cout << 1 << "\n";
          } else {
               cout << 2 << "\n";
          }

     }

}


#include <bits/stdc++.h>

using namespace std;

int main(){

     int t; cin >> t;

     for(int i=0; i<t; i++){
          int n, x; cin >> n >> x;
          vector<int> v;
          for (int j=0; j<n; j++){
               int a; cin >> a;
               v.push_back(a);
          }

          int count = 0;
          int diffSum = 0;

          for (int j=0; j<n; j++){
               if(v[j] == x){
                    count++;
               }
               diffSum+=(x - v[j]);
          }
          if(count == n){
               cout << 0 << "\n";
          } else if(diffSum == 0 && count!= n){
               cout << 1 << "\n";
          } else {
               cout << 2 << "\n";
          }

     }

}


#include <bits/stdc++.h>

using namespace std;

int main(){
     int T;
    cin >> T;
    while (T > 0) {
        int n, x;
        cin >> n >> x;
        int cnt = 0;
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            int val;
            cin >> val;
            cnt += (val == x);
            sum += val;
        }
        if (cnt == n) {
            cout << 0 << '\n';
        } else if (cnt > 0) {
            cout << 1 << '\n';
        } else if (sum == n * x) {
            cout << 1 << '\n';
        } else {
            cout << 2 << '\n';
        }
        T--;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main(){

     int t; cin >> t;

     for(int i=0; i<t; i++){
          int n, x; cin >> n >> x;
          vector<int> v;
          for (int j=0; j<n; j++){
               int a; cin >> a;
               v.push_back(a);
          }

          int count = 0;
          int diffSum = 0;

          for (int j=0; j<n; j++){
               if(v[i] == x){
                    count++;
               }
               diffSum+=(x - v[j]);
          }
          if(count == n){
               cout << 0;
          } else if(diffSum == 0 && count!= n){
               cout << 1;
          } else {
               cout << 2;
          }

     }

}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
const int N=100005;
int n,x,k;
int a[1005];
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tt;cin>>tt;
    while(tt--) {
        cin>>n>>x;
        int cnt=0;
        vector<int> arr;
        map<int,int> m;
        for(int i=0;i<n;i++) {
            cin>>a[i];
            m[a[i]]++;
        }
        sort(a,a+n);
        for(int i=0;i<n;i++) {
            if(m[a[i]]==1) arr.push_back(a[i]);
        }
        int len=arr.size();
        if(len==0) {
            cout<<len<<'\n';
            continue;
        }
        int sum=0;
        for(int i=0;i<len-1;i++) {
            sum+=arr[i]-x;
        }
        cout<<(arr[len-1]+sum==x?1:2)<<'\n';
    }
    return 0;
}
/*
1
9 38
-21 83 50 -59 -77 15 -71 -78 20
*/


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
const int N=100005;
int n,x,k;
int a[1005];
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tt;cin>>tt;
    while(tt--) {
        cin>>n>>x;
        int cnt=0;
        map<int,int> m;
        for(int i=0;i<n;i++) {
            cin>>a[i];
            if(a[i]==x) cnt++;
        }
        sort(a,a+n);
        int sum=0;
        for(int i=0;i<n;i++) {
            if(m[a[i]]>1) continue;
            sum+=a[i]-x;
        }
        if(cnt==n) cout<<0<<'\n';
        else if(cnt>0||sum==0) cout<<1<<'\n';
        else cout<<2<<'\n';
    }
    return 0;
}
/*
1
9 38
-21 83 50 -59 -77 15 -71 -78 20
*/


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
const int N=100005;
int n,x;
int arr[1005];
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tt;cin>>tt;
    while(tt--) {
        cin>>n>>x;
        for(int i=0;i<n;i++) cin>>arr[i];
        sort(arr,arr+n);
        if(arr[0]==x&&arr[n-1]==x) {
            cout<<0<<'\n';
            continue;
        }
        int sum=0;
        for(int i=0;i<n-1;i++) {
            sum+=arr[i]-x;
        }
        cout<<(arr[n-1]+sum==x?1:2)<<'\n';
    }
    return 0;
}
/*
1
9 38
-21 83 50 -59 -77 15 -71 -78 20
*/


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
const int N=100005;
int n,x,k;
int a[1005];
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tt;cin>>tt;
    while(tt--) {
        cin>>n>>x;
        int cnt=0;
        map<int,int> m;
        for(int i=0;i<n;i++) {
            cin>>a[i];
            m[a[i]]++;
            if(m[a[i]]>1) cnt++;
        }
        sort(a,a+n);
        int sum=0,ok=0;
        for(int i=0;i<n;i++) {
            if(m[a[i]]>1) continue;
            sum+=a[i]-x;
            ok=1;
        }
        if(!sum) cout<<sum+ok<<'\n';
        else {
            if(cnt) cout<<1<<'\n';
            else cout<<2<<'\n';
        }
    }
    return 0;
}
/*
1
9 38
-21 83 50 -59 -77 15 -71 -78 20
*/


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
const int N=100005;
int n,x;
int arr[1005];
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tt;cin>>tt;
    while(tt--) {
        cin>>n>>x;
        int cnt=0;
        for(int i=0;i<n;i++) {
            cin>>arr[i];
            if(arr[i]==x) cnt++;
        }
        sort(arr,arr+n);
        if(arr[0]==x&&arr[n-1]==x) {
            cout<<0<<'\n';
            continue;
        }
        int sum=0;
        for(int i=0;i<n;i++) {
            sum+=arr[i]-x;
        }
        if(cnt>0||sum==0) cout<<1<<'\n';
        else cout<<2<<'\n';
    }
    return 0;
}
/*
1
9 38
-21 83 50 -59 -77 15 -71 -78 20
*/


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
typedef long long ll;
using namespace std;
const int N=100005;
int n,x;
struct team {
    int v;
    bool operator < (const team& X) const {
        return abs(v-x)<abs(X.v-x);
    }
}arr[1005];
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tt;cin>>tt;
    while(tt--) {
        cin>>n>>x;
        for(int i=0;i<n;i++) cin>>arr[i].v;
        sort(arr,arr+n);
        if(arr[0].v==x&&arr[1].v==x) {
            cout<<0<<'\n';
            continue;
        }
        int sum=0;
        for(int i=0;i<n-1;i++) sum+=arr[i].v-x;
        cout<<(arr[n-1].v+sum==x?1:2)<<'\n';
    }
    return 0;
}
/*
1
5
3 -4 1 -2 -5
*/


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
const int N=100005;
ll n,x;
ll arr[1005];
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tt;cin>>tt;
    while(tt--) {
        cin>>n>>x;
        for(int i=0;i<n;i++) cin>>arr[i];
        sort(arr,arr+n);
        if(arr[0]==x&&arr[n-1]==x) {
            cout<<0<<'\n';
            continue;
        }
        ll sum=0;
        for(int i=0;i<n-1;i++) {
            sum+=arr[i]-x;
        }
        cout<<(arr[n-1]+sum==x?1:2)<<'\n';
    }
    return 0;
}
/*
1
9 38
-21 83 50 -59 -77 15 -71 -78 20
*/


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
ll t, n, x, a[1007];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> t;
    while(t--) {
        cin >> n >> x;
        for(ll i = 0; i < n; ++i) cin >> a[i];

        bool ok = 0;
        for(ll i = 1; i < n; ++i) {
            if(a[i] != a[i - 1]) {
                ok = 1;
                break;
            }
        }

        if(!ok && a[0] == x) {
            cout << 0 << '\n';
            continue;
        }

        ll sum = 0;
        for(ll i = 0; i < n; ++i) sum += (x - a[i]);

        bool flag = 0;
        for(ll i = 0; i < n; ++i) {
            if(sum - (x - a[i]) == a[i] - x) {
                flag = 1;
                break;
            }
        }

        if(flag) cout << 1 << '\n';
        else cout << 2 << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
ll t, n, x, a[1007];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> t;
    while(t--) {
        cin >> n >> x;
        for(ll i = 0; i < n; ++i) cin >> a[i];

        bool ok = 0;
        for(ll i = 1; i < n; ++i) {
            if(a[i] != a[i - 1]) {
                ok = 1;
                break;
            }
        }

        if(!ok) {
            cout << 0 << '\n';
            continue;
        }

        ll sum = 0;
        for(ll i = 0; i < n - 1; ++i) sum += (x - a[i]);

        if(a[n - 1] - x == sum) {
            cout << 1 << '\n';
            continue;
        }

        cout << 2 << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
ll t, n, x, a[1007];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> t;
    while(t--) {
        //memset(pref, 0, sizeof(pref));

        cin >> n >> x;
        for(ll i = 0; i < n; ++i) cin >> a[i];

        bool ok = 0;
        for(ll i = 1; i < n; ++i) {
            if(a[i] != a[i - 1]) {
                ok = 1;
                break;
            }
        }

        if(!ok && a[0] == x) {
            cout << 0 << '\n';
            continue;
        }

        ll sum = 0;
        for(ll i = 0; i < n; ++i) sum += a[i];

        if(sum == n * x) cout << 1 << '\n';
        else cout << 2 << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
ll t, n, x, a[1007];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> t;
    while(t--) {
        //memset(pref, 0, sizeof(pref));

        cin >> n >> x;
        for(ll i = 0; i < n; ++i) cin >> a[i];

        sort(a, a + n);

        if(a[0] == a[n - 1] && a[0] == x) {
            cout << 0 << '\n';
            continue;
        }

        ll sum = 0;
        for(ll i = 0; i < n; ++i) sum += a[i];

        if(sum == n * x) cout << 1 << '\n';
        else cout << 2 << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
ll t, n, x, a[1007], pref[1007];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> t;
    while(t--) {
        memset(pref, 0, sizeof(pref));

        cin >> n >> x;
        for(ll i = 0; i < n; ++i) cin >> a[i];

        bool ok = 0;
        for(ll i = 1; i < n; ++i) {
            if(a[i] != a[i - 1]) {
                ok = 1;
                break;
            }
        }

        if(!ok && a[0] == x) {
            cout << 0 << '\n';
            continue;
        }

        pref[0] = (x - a[0]);
        for(ll i = 1; i < n; ++i) pref[i] = pref[i - 1] + (x - a[i]);

        bool flag = 0;
        for(ll i = 0; i < n; ++i) {
            for(ll j = i; j < n; ++j) {
                if(i == 0) {
                    if(pref[j] == -1 * pref[n - 1]) {
                        flag = 1;
                        break;
                    }
                } else {
                    if(pref[j] - pref[i - 1] == -1 * pref[n - 1]) {
                        flag = 1;
                        break;
                    }
                }
            }

            if(flag) break;
        }

        if(flag) cout << 1 << '\n';
        else cout << 2 << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
ll t, n, x, a[1007];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> t;
    while(t--) {
        //memset(pref, 0, sizeof(pref));

        cin >> n >> x;
        for(ll i = 0; i < n; ++i) cin >> a[i];

        sort(a, a + n);

        ll cnt = 0;
        for(ll i = 0; i < n; ++i) {
            if(a[i] == x) cnt++;
        }

        if(a[0] == a[n - 1] && a[0] == x) {
            cout << 0 << '\n';
            continue;
        }

        if(cnt >= 1) {
            cout << 1 << '\n';
            continue;
        }

        ll sum = 0;
        for(ll i = 0; i < n; ++i) sum += a[i];

        if(sum == n * x) cout << 1 << '\n';
        else cout << 2 << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
ll t, n, x, a[1007];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> t;
    while(t--) {
        //memset(pref, 0, sizeof(pref));

        cin >> n >> x;
        for(ll i = 0; i < n; ++i) cin >> a[i];

        sort(a, a + n);

        ll cnt = 0;
        for(ll i = 0; i < n; ++i) {
            if(a[i] != x) cnt++;
        }

        if(cnt == 1) {
            cout << 1 << '\n';
            continue;
        }

        if(a[0] == a[n - 1] && a[0] == x) {
            cout << 0 << '\n';
            continue;
        }

        ll sum = 0;
        for(ll i = 0; i < n; ++i) sum += a[i];

        if(sum == n * x) cout << 1 << '\n';
        else cout << 2 << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
ll t, n, x, a[1007];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> t;
    while(t--) {
        cin >> n >> x;
        for(ll i = 0; i < n; ++i) cin >> a[i];

        bool ok = 0;
        for(ll i = 1; i < n; ++i) {
            if(a[i] != a[i - 1]) {
                ok = 1;
                break;
            }
        }

        if(!ok && a[0] == x) {
            cout << 0 << '\n';
            continue;
        }

        ll sum = 0;
        for(ll i = 0; i < n - 1; ++i) sum += (x - a[i]);

        if(a[n - 1] - x == sum) {
            cout << 1 << '\n';
            continue;
        }

        cout << 2 << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
typedef vector<int> VI;
const ll mod=1000000007;
const int maxn=2e3+10;
const int inf=0x3f3f3f3f;
ll gcd(ll a,ll b) {
    return b?gcd(b,a%b):a;
}
#define ms(a) memset(a,0,sizeof(a))
#define mss(a) memset(a,-1,sizeof(a))
#define msi(a) memset(a,inf,sizeof(a))
#define iossync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head
int T;
ll n,m;
ll a[2000];
ll b;
int main()
{
	cin>>T;
//	while(T--)
	rep(z,1,T+1)
	{
//		if(z==4 && T==1000)
		cin>>n>>m;
		if(z==4 && T==100)
		cout<<n<<" "<<m<<"\n";
		ll cnt=0;
		ll sum=0;
		rep(i,0,n)
		{
//			if(z==4 && T==1000)
			cin>>b;
			if(z==4 && T==100)
			cout<<b<<" ";
			if(b!=m)
			{
				sum+=b;
				a[cnt++]=b;
			}
		}
		cout<<"\n";
		if((z==4 && T==100 ) || T==3)
		;
		else
		continue;
//			cout<<b<<" ";
		if((m*cnt)==sum)
		{
			if(cnt)
			{
				cout<<"1\n";
			}
			else
			cout<<"0\n";
		}
		else
		{
			if(cnt==1)
			cout<<"1\n";
			else
			cout<<"2\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
typedef vector<int> VI;
const ll mod=1000000007;
const int maxn=2e3+10;
const int inf=0x3f3f3f3f;
ll gcd(ll a,ll b) {
    return b?gcd(b,a%b):a;
}
#define ms(a) memset(a,0,sizeof(a))
#define mss(a) memset(a,-1,sizeof(a))
#define msi(a) memset(a,inf,sizeof(a))
#define iossync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head
int T;
ll n,m;
ll a[2000];
ll b;
int main()
{
	cin>>T;
//	while(T--)
	rep(z,1,T+1)
	{
//		if(z==4 && T==1000)
		cin>>n>>m;
//		if(z==4 && T==100)
//		cout<<n<<" "<<m<<"\n";
		ll cnt=0;
		ll sum=0;
		rep(i,0,n)
		{
//			if(z==4 && T==1000)
			cin>>b;
//			if(z==4 && T==100)
//			cout<<b<<" ";
			if(b!=m)
			{
				sum+=b;
				a[cnt++]=b;
			}
		}
//		cout<<"\n";
//		if((z==4 && T==100 ) || T==3)
//		;
//		else
//		continue;
//			cout<<b<<" ";
		if((m*cnt)==sum)
		{
			if(cnt)
			{
				cout<<"1\n";
			}
			else
			cout<<"0\n";
		}
		else
		{
			if(cnt<n)
			cout<<"1\n";
			else
			cout<<"2\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
typedef vector<int> VI;
const ll mod=1000000007;
const int maxn=2e3+10;
const int inf=0x3f3f3f3f;
ll gcd(ll a,ll b) {
    return b?gcd(b,a%b):a;
}
#define ms(a) memset(a,0,sizeof(a))
#define mss(a) memset(a,-1,sizeof(a))
#define msi(a) memset(a,inf,sizeof(a))
#define iossync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head
int T;
ll n,m;
ll a[2000];
ll b;
int main()
{
	cin>>T;
//	while(T--)
	rep(z,1,T+1)
	{
//		if(z==4 && T==1000)
		cin>>n>>m;
		if(z==4 && T==1000)
		cout<<n<<" "<<m<<"\n";
		ll cnt=0;
		ll sum=0;
		rep(i,0,n)
		{
//			if(z==4 && T==1000)
			cin>>b;
			if(z==4 && T==1000)
			cout<<b<<" ";
			if(b!=m)
			{
				sum+=b;
				a[cnt++]=b;
			}
		}
		cout<<"\n";
		if((z==4 && T==1000 ) || T==3)
		;
		else
		continue;
//			cout<<b<<" ";
		if((m*cnt)==sum)
		{
			if(cnt)
			{
				cout<<"1\n";
			}
			else
			cout<<"0\n";
		}
		else
		{
			if(cnt==1)
			cout<<"1\n";
			else
			cout<<"2\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
typedef vector<int> VI;
const ll mod=1000000007;
const int maxn=2e3+10;
const int inf=0x3f3f3f3f;
ll gcd(ll a,ll b) {
    return b?gcd(b,a%b):a;
}
#define ms(a) memset(a,0,sizeof(a))
#define mss(a) memset(a,-1,sizeof(a))
#define msi(a) memset(a,inf,sizeof(a))
#define iossync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head
int T;
ll n,m;
ll a[2000];
ll b;
int main()
{
	cin>>T;
	while(T--)
	{
		cin>>n>>m;
		ll cnt=0;
		ll sum=0;
		rep(i,0,n)
		{
			cin>>b;
			if(b!=m)
			{
				sum+=b;
				a[cnt++]=b;
			}
		}
		if((m*cnt)==sum)
		{
			if(cnt)
			{
				cout<<"1\n";
			}
			else
			cout<<"0\n";
		}
		else
		{
			if(cnt==1)
			cout<<"1\n";
			else
			cout<<"2\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
typedef vector<int> VI;
const ll mod=1000000007;
const int maxn=2e3+10;
const int inf=0x3f3f3f3f;
ll gcd(ll a,ll b) {
    return b?gcd(b,a%b):a;
}
#define ms(a) memset(a,0,sizeof(a))
#define mss(a) memset(a,-1,sizeof(a))
#define msi(a) memset(a,inf,sizeof(a))
#define iossync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head
int T;
ll n,m;
ll a[2000];
ll b;
int main()
{
	cin>>T;
	while(T--)
	{
		cin>>n>>m;
		int cnt=0;
		ll sum=0;
		rep(i,0,n)
		{
			cin>>b;
			if(b!=m)
			{
				sum+=b;
				a[cnt++]=b;
			}
		}
		if(m*cnt==sum)
		{
			if(cnt)
			{
				cout<<"1\n";
			}
			else
			cout<<"0\n";
		}
		else
		{
			if(cnt==1)
			cout<<"1\n";
			else
			cout<<"2\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
typedef vector<int> VI;
const ll mod=1000000007;
const int maxn=2e3+10;
const int inf=0x3f3f3f3f;
ll gcd(ll a,ll b) {
    return b?gcd(b,a%b):a;
}
#define ms(a) memset(a,0,sizeof(a))
#define mss(a) memset(a,-1,sizeof(a))
#define msi(a) memset(a,inf,sizeof(a))
#define iossync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head
int T;
ll n,m;
ll a[2000];
ll b;
int main()
{
	cin>>T;
//	while(T--)
	rep(z,1,T+1)
	{
//		if(z==4 && T==1000)
		cin>>n>>m;
		if(z==4 && T==1000)
		cout<<n<<" "<<m<<"\n";
		ll cnt=0;
		ll sum=0;
		rep(i,0,n)
		{
//			if(z==4 && T==1000)
			cin>>b;
			if(z==4 && T==1000)
			cout<<b<<" ";
			if(b!=m)
			{
				sum+=b;
				a[cnt++]=b;
			}
		}
		cout<<"\n";
		if(z==4 && T==1000)
		;
		else
		continue;
//			cout<<b<<" ";
		if((m*cnt)==sum)
		{
			if(cnt)
			{
				cout<<"1\n";
			}
			else
			cout<<"0\n";
		}
		else
		{
			if(cnt==1)
			cout<<"1\n";
			else
			cout<<"2\n";
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()

int main(int argc, char const *argv[])
{
//	#define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
	#endif
	LL _;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>_;

	while(_--){
		int n;
		int bad;

		cin>>n;
		cin>>bad;

		vector<int> a(n);
		bool ans = false;
		bool hasbig = false;
		bool hassmall = false;
		int sum = 0;
		bool has = false;
		for(int i=0; i<n; i++){
			cin>>a[i];
			sum += a[i];
			if(a[i]==bad) has=true;
			if(a[i]!=bad) ans = true;
			if(a[i]>=bad) hasbig = true;
			if(a[i]<=bad) hassmall = true;
		}
		if(!ans){
			cout<<0<<endl;
		}
		else if(sum==bad*n||has&&sum%n==0){
			cout<<1<<endl;
		}else
			cout<<2<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()

int main(int argc, char const *argv[])
{
//	#define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
	#endif
	LL _;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>_;

	while(_--){
		int n;
		int bad;

		cin>>n;
		cin>>bad;

		vector<int> a(n);
		bool ans = false;
		int sum = 0;
		for(int i=0; i<n; i++){
			cin>>a[i];
			sum += a[i];
			if(a[i]!=bad) ans = true;
		}
		if(!ans){
			cout<<0<<endl;
		}
		else if(sum==bad*n){
			cout<<1<<endl;
		}else{
			cout<<2<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()

int main(int argc, char const *argv[])
{
//	#define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
	#endif
	LL _;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>_;

	while(_--){
		int n;
		int bad;

		cin>>n;
		cin>>bad;

		vector<int> a(n);
		bool ans = false;
		bool hasbig = false;
		bool hassmall = false;
		int sum = 0;
		bool has = false;
		for(int i=0; i<n; i++){
			cin>>a[i];
			sum += a[i];
			if(a[i]==bad) has=true;
			if(a[i]!=bad) ans = true;
			if(a[i]>=bad) hasbig = true;
			if(a[i]<=bad) hassmall = true;
		}
		if(!ans){
			cout<<0<<endl;
		}
		else if(sum==bad*n||has&&sum%n==0){
			cout<<1<<endl;
		}else
			cout<<2<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()

int main(int argc, char const *argv[])
{
//	#define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
	#endif
	LL _;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>_;

	while(_--){
		int n;
		int bad;

		cin>>n;
		cin>>bad;

		vector<int> a;
		int num;
		bool ans = false;
		bool hasbig = false;
		bool hassmall = false;
		int sum = 0;
		bool has = false;
		for(int i=0; i<n; i++){
			cin>>num;
			if(num==bad) has=true;
			if(num!=bad){
				sum += num;
				a.push_back(num);
			}
		}
		sort(all(a));
		if(!a.size()){
			cout<<0<<endl;
		}
		else if(sum==bad*a.size()||a.size()!=n){
			cout<<1<<endl;
		}else
			cout<<2<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()

int main(int argc, char const *argv[])
{
//	#define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
	#endif
	LL _;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>_;

	while(_--){
		int n;
		int bad;

		cin>>n;
		cin>>bad;

		vector<int> a;
		int num;
		bool ans = false;
		bool hasbig = false;
		bool hassmall = false;
		int sum = 0;
		bool has = false;
		for(int i=0; i<n; i++){
			cin>>num;
			if(num==bad) has=true;
			if(num!=bad){
				sum += num;
				a.push_back(num);
			}
		}
		sort(all(a));
		if(!ans){
			cout<<0<<endl;
		}
		else if(sum==bad*a.size()||a.size()!=n){
			cout<<1<<endl;
		}else
			cout<<2<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()

int main(int argc, char const *argv[])
{
//	#define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
	#endif
	LL _;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>_;

	while(_--){
		int n;
		int bad;

		cin>>n;
		cin>>bad;

		vector<int> a(n);
		bool ans = false;
		bool hasbig = false;
		bool hassmall = true;
		int sum = 0;
		for(int i=0; i<n; i++){
			cin>>a[i];
			sum += a[i];
			if(a[i]!=bad) ans = true;
			if(a[i]>=bad) hasbig = true;
			if(a[i]<=bad) hassmall = true;
		}
		if(!ans){
			cout<<0<<endl;
		}
		else if(sum==bad*n){
			cout<<1<<endl;
		}else if(hasbig&&hassmall||sum%n==0){
			cout<<2<<endl;
		}else{
			cout<<3<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()

int main(int argc, char const *argv[])
{
//	#define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
	#endif
	LL _;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>_;

	while(_--){
		int n;
		int bad;

		cin>>n;
		cin>>bad;

		vector<int> a(n);
		bool ans = false;
		bool hasbig = false;
		bool hassmall = false;
		int sum = 0;
		bool has = false;
		for(int i=0; i<n; i++){
			cin>>a[i];
			sum += a[i];
			if(a[i]==bad) has=true;
			if(a[i]!=bad) ans = true;
			if(a[i]>=bad) hasbig = true;
			if(a[i]<=bad) hassmall = true;
		}
		if(!ans){
			cout<<0<<endl;
		}
		else if(sum==bad*n||has&&sum%n==0){
			cout<<1<<endl;
		}else if(hasbig&&hassmall||sum%n==0){
			cout<<2<<endl;
		}else{
			cout<<3<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()

int main(int argc, char const *argv[])
{
//	#define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
	#endif
	LL _;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>_;

	while(_--){
		int n;
		int bad;

		cin>>n;
		cin>>bad;

		vector<int> a(n);
		bool ans = false;
		bool hasbig = false;
		bool hassmall = false;
		int sum = 0;
//		bool same = false;
		for(int i=0; i<n; i++){
			cin>>a[i];
			sum += a[i];
			if(a[i]!=bad) ans = true;
			if(a[i]>=bad) hasbig = true;
			if(a[i]<=bad) hassmall = true;
		}
		if(!ans){
			cout<<0<<endl;
		}
		else if(sum==bad*n){
			cout<<1<<endl;
		}else if(hasbig&&hassmall||sum%n==0){
			cout<<2<<endl;
		}else{
			cout<<3<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int t, i, n, x, k, j, p, s, a;
    bool c;
    cin >> t;
    for (p = 0; p < t; ++p){
        cin >> n >> x;
        k = 0; s = 0;
        for (i = 0; i < n; ++i){
            cin >> a;
            s += a;
            if (a == x)
                ++k;

        }
        if (k == n)
            cout << 0;
        else{
            if (s == x * n || k > 0){
                cout << 1;
            }else{
                cout << 2;
            }
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t, i, n, x, k, j, p, s, a;
    bool c;
    cin >> t;
    for (p = 0; p < t; ++p){
        cin >> n >> x;
        k =0;
        for (i = 0; i < n; ++i){
            cin >> a;
            s += a;
            if (a == x)
                ++k;

        }
        if (k == n)
            cout << 0;
        else{
            if (s == x * n){
                cout << 1;
            }else{
                if (k == 0)
                    cout << 2;
                else {
                    j = s - n * x;
                    c = false;
                    for (i = n - k + 1; i <= n; ++j){
                        if (j % i == 0)
                            c = true;
                    }
                    if (c)
                        cout << 1;
                    else cout << 2;
                }
            }
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int t, i, n, x, k, j, p, s, a;
    bool c;
    cin >> t;
    for (p = 0; p < t; ++p){
        cin >> n >> x;
        k = 0; s = 0;
        for (i = 0; i < n; ++i){
            cin >> a;
            s += a;
            if (a == x)
                ++k;

        }
        if (k == n)
            cout << 0;
        else{
            if (s == x * n){
                cout << 1;
            }else{
                if (k == 0)
                    cout << 2;
                else {
                    j = s - n * x;
                    c = false;
                    for (i = n - k + 1; i <= n; ++j){
                        if (j % i == 0)
                            c = true;
                    }
                    if (c)
                        cout << 1;
                    else cout << 2;
                }
            }
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int t, i, n, x, k, j, p, s, a;
    bool c;
    cin >> t;
    for (p = 0; p < t; ++p){
        cin >> n >> x;
        k =0;
        for (i = 0; i < n; ++i){
            cin >> a;
            s += a;
            if (a == x)
                ++k;

        }
        if (k == n)
            cout << 0;
        else{
            if (s == x * n){
                cout << 1;
            }else{
                if (k == 0)
                    cout << 2;
                else {
                    j = s - n * x;
                    c = false;
                    for (i = n - k + 1; i <= n; ++j){
                        if (j % i == 0)
                            c = true;
                    }
                    if (c)
                        cout << 1;
                    else cout << 2;
                }
            }
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int t, i, n, x, k, j, p, s, a;
    bool c;
    cin >> t;
    for (p = 0; p < t; ++p){
        cin >> n >> x;
        k = 0; s = 0;
        for (i = 0; i < n; ++i){
            cin >> a;
            s += a;
            if (a == x)
                ++k;

        }
        if (k == n)
            cout << 0;
        else{
            if (s == x * n){
                cout << 1;
            }else{
                if (k == 0)
                    cout << 2;
                else {
                    j = s - n * x;
                    c = false;
                    for (i = n - k + 1; i <= n; ++j){
                        if (j % i == 0)
                            c = true;
                    }
                    if (c)
                        cout << 1;
                    else cout << 2;
                }
            }
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int t, i, n, x, k, j, p, s, a;
    bool c;
    cin >> t;
    for (p = 0; p < t; ++p){
        cin >> n >> x;
        k = 0; s = 0;
        for (i = 0; i < n; ++i){
            cin >> a;
            s += a;
            if (a == x)
                ++k;

        }
        if (k == n)
            cout << 0;
        else{
            if (s == x * n){
                cout << 1;
            }else{
                if (k == 0)
                    cout << 2;
                else {
                    j = s - n * x;
                    c = false;
                    for (i = 2; i * i <= n && c == false; ++j){
                        if (j % i == 0 && ((i > n - k && i <= n) || (j / i > n - k && j / i <= n)))
                            c = true;
                    }
                    if (c)
                        cout << 1;
                    else cout << 2;
                }
            }
        }
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ls o<<1
#define rs o<<1|1
const int maxn=1e3+5;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;

int a[maxn];
int n,x;
bool ck(){
	for(int i=1;i<=n;i++)
		if(a[i]!=x){
			return false;
		}
	return true;
}
bool ck2(){
	int sum=0;
	for(int i=1;i<=n;i++)
		sum+=a[i];
	if(sum==x*n)
		return true;
	else return false;
}
void solve(){
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	if(ck()){
		printf("0\n");
		return ;
	}
	if(ck2()){
		printf("1\n");
		return ;
	}
	printf("2\n");
}
int main(){
	int T;scanf("%d",&T);while(T--)
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ls o<<1
#define rs o<<1|1
const int maxn=1e3+5;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;

ll a[maxn];
ll n,x;
bool ck(){
	for(int i=1;i<=n;i++){
		if(a[i]!=x){
			return false;
		}
	}
	return true;
}
bool ck2(){
	ll sum=0;
	int cnt=0,cntx=0;
	for(int i=1;i<=n;i++){
		if(a[i]!=x){
		sum+=a[i];
		cnt++;
	    }
	    else cntx++;
	}
    if(cntx)
    	return true;
    else{
	if(sum==x*n)
		return true;
	else return false;
    }
}
void solve(){
	scanf("%lld%lld",&n,&x);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	if(ck()){
		printf("0\n");
		return ;
	}
	if(ck2()){
		printf("1\n");
		return ;
	}
	printf("2\n");
}
int main(){
	int T;scanf("%d",&T);while(T--)
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ls o<<1
#define rs o<<1|1
const int maxn=1e3+5;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;

int a[maxn],vis[maxn];
int n,x;
bool ck(){
	for(int i=1;i<=n;i++)
		if(a[i]!=x){
			return false;
		}
	return true;
}
bool ck2(){
	for(int i=1;i<=n;i++)
		vis[i]=0;
	for(int i=1;i<=n;i++){
		if(a[i]==x){
			vis[i]=1;
			continue;
		}
		if(vis[i]) continue;
		int j;
		for(j=i+1;j<=n;j++){
			if(vis[j]) continue;
			if(a[i]+a[j]==2*x){
				vis[i]=vis[j]=1;
				break;
			}
		}
		if(j==n+1)
			return false;
	}
	return true;
}
void solve(){
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	if(ck()){
		printf("0\n");
		return ;
	}
	if(ck2()){
		printf("1\n");
		return ;
	}
	if(n&1){
		for(int i=1;i<=n;i++){
			if(a[i]==x){
				printf("2\n");
				return ;
			}
		}
		printf("3\n");
		return ;
	}
	printf("2\n");
}
int main(){
	int T;scanf("%d",&T);while(T--)
	solve();
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 1005
int root[N];
void Init()
{
	for (int i = 0; i < N; ++ i)
		root[i] = i;
}
int Find(int x)
{
	if (root[x] != x) root[x] = Find(root[x]);
	return root[x];
}
void Merge(int x, int y)
{
	int fx = Find(x), fy = Find(y);
	if (fx != fy) root[fx] = fy;
}
int n, x, nx, an;
int num[N], gn;
bool vis[N], ans[N];
bool v[N][N];
void dfs(int d, int sum, int ind)
{
	ans[sum+nx] = 1;
	if (d == gn) return ;
	for (int i = ind; i <= gn; ++ i) if (!vis[i] && (vis[i-1]||num[i]!=num[i-1]))
	{
		vis[i] = 1;
		if (!v[ind][sum+num[i]]) dfs(d+1, sum+num[i], ind+1);
		v[ind][sum+num[i]] = 1;
		vis[i] = 0;
	}
}
int main()
{
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	while (scanf("%d%d",&n,&x) != EOF)
	{
		Init();
		memset(num, 0, sizeof(num));
		for (int i=1,a; i <= n; ++ i)
		{
			scanf("%d", &a);
			if (a!=0) root[i] = a;
		}
		nx = 1;
		while (root[x] != x)
		{
			nx ++;
			x = root[x];
		}
		for (int i = 1; i <= n; ++ i)
			num[Find(i)] ++;
		num[gn=0] = 0;
		for (int i = 1; i <= n; ++ i)
			if (i != x && num[i] != 0) num[++gn] = num[i];
		sort(num+1, num+gn+1);
		memset(vis, 0, sizeof(vis));
		memset(ans, 0, sizeof(ans));
		memset(v, 0, sizeof(v));
		dfs(0,0,1);
		an = 0;
		for (int i = 1; i <= n; ++ i)
			if (ans[i]) printf("%d\n", i);
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 1005
int root[N];
void Init()
{
	for (int i = 0; i < N; ++ i)
		root[i] = i;
}
int Find(int x)
{
	if (root[x] != x) root[x] = Find(root[x]);
	return root[x];
}
void Merge(int x, int y)
{
	int fx = Find(x), fy = Find(y);
	if (fx != fy) root[fx] = fy;
}
int n, x, nx, an;
int num[N], gn;
bool vis[N], ans[N];
bool v[N][N];
void dfs(int d, int sum, int ind)
{
	ans[sum+nx] = 1;
	if (d == gn) return ;
	for (int i = ind; i <= gn; ++ i) if (!vis[i] && (vis[i-1]||num[i]!=num[i-1]))
	{
		vis[i] = 1;
		if (!v[ind][sum+num[i]]) dfs(d+1, sum+num[i], ind+1);
		v[ind][sum+num[i]] = 1;
		vis[i] = 0;
	}
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	while (scanf("%d%d",&n,&x) != EOF)
	{
		Init();
		memset(num, 0, sizeof(num));
		for (int i=1,a; i <= n; ++ i)
		{
			scanf("%d", &a);
			if (a!=0) root[i] = a;
		}
		nx = 1;
		while (root[x] != x)
		{
			nx ++;
			x = root[x];
		}
		for (int i = 1; i <= n; ++ i)
			num[Find(i)] ++;
		num[gn=0] = 0;
		for (int i = 1; i <= n; ++ i)
			if (i != x && num[i] != 0) num[++gn] = num[i];
		sort(num+1, num+gn+1);
		memset(vis, 0, sizeof(vis));
		memset(ans, 0, sizeof(ans));
		memset(v, 0, sizeof(v));
		dfs(0,0,1);
		an = 0;
		for (int i = 1; i <= n; ++ i)
			if (ans[i]) printf("%d\n", i);
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 1005
int root[N];
void Init()
{
	for (int i = 0; i < N; ++ i)
		root[i] = i;
}
int Find(int x)
{
	if (root[x] != x) root[x] = Find(root[x]);
	return root[x];
}
void Merge(int x, int y)
{
	int fx = Find(x), fy = Find(y);
	if (fx != fy) root[fx] = fy;
}
int n, x, nx;
int num[N], gn;
bool ans[N];
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	while (scanf("%d%d",&n,&x) != EOF)
	{
		Init();
		memset(num, 0, sizeof(num));
		for (int i=1,a; i <= n; ++ i)
		{
			scanf("%d", &a);
			if (a!=0) root[i] = a;
		}
		nx = 1;
		while (root[x] != x)
		{
			nx ++;
			x = root[x];
		}
		for (int i = 1; i <= n; ++ i)
			num[Find(i)] ++;
		gn = 0;
		for (int i = 1; i <= n; ++ i)
			if (i != x && num[i] != 0) num[gn++] = num[i];
		//for (int i = 0; i < gn; ++ i)
		//	printf("%d ", num[i]);
		memset(ans, 0, sizeof(ans));
		ans[nx] = 1;
		for (int i = 0; i < gn; ++ i)
			for (int j = 1000; j >= 0; -- j)
				if (ans[j]) ans[j+num[i]] = 1;
		for (int i = 1; i <= n; ++ i)
			if (ans[i]) printf("%d\n", i);
	}
}


#include <cstdio>
#include <cstring>
#define N 1005
int root[N];
void Init()
{
	for (int i = 0; i < N; ++ i)
		root[i] = i;
}
int Find(int x)
{
	if (root[x] != x) root[x] = Find(root[x]);
	return root[x];
}
void Merge(int x, int y)
{
	int fx = Find(x), fy = Find(y);
	if (fx != fy) root[fx] = fy;
}
int n, x, nx, an;
int num[N], gn;
bool vis[N], ans[N];
void dfs(int d, int sum)
{
	ans[sum+nx] = 1;
	if (d == gn) return ;
	for (int i = 0; i < gn; ++ i) if (!vis[i])
	{
		vis[i] = 1;
		dfs(d+1, sum+num[i]);
		vis[i] = 0;
	}
}
int main()
{
	while (scanf("%d%d",&n,&x) != EOF)
	{
		Init();
		memset(num, 0, sizeof(num));
		for (int i=1,a; i <= n; ++ i)
		{
			scanf("%d", &a);
			if (a!=0) root[i] = a;
		}
		nx = 1;
		while (root[x] != x)
		{
			nx ++;
			x = root[x];
		}
		for (int i = 1; i <= n; ++ i)
			num[Find(i)] ++;
		gn = 0;
		for (int i = 1; i <= n; ++ i)
			if (i != x && num[i] != 0) num[gn++] = num[i];
		memset(vis, 0, sizeof(vis));
		memset(ans, 0, sizeof(ans));
		dfs(0,0);
		an = 0;
		for (int i = 1; i <= n; ++ i)
			if (ans[i]) printf("%d\n", i);
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 1005
int root[N];
void Init()
{
	for (int i = 0; i < N; ++ i)
		root[i] = i;
}
int Find(int x)
{
	if (root[x] != x) root[x] = Find(root[x]);
	return root[x];
}
void Merge(int x, int y)
{
	int fx = Find(x), fy = Find(y);
	if (fx != fy) root[fx] = fy;
}
int n, x, nx;
int num[N], gn;
bool ans[N];
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	while (scanf("%d%d",&n,&x) != EOF)
	{
		Init();
		memset(num, 0, sizeof(num));
		for (int i=1,a; i <= n; ++ i)
		{
			scanf("%d", &a);
			if (a!=0) root[i] = a;
		}
		nx = 1;
		while (root[x] != x)
		{
			nx ++;
			x = root[x];
		}
		for (int i = 1; i <= n; ++ i)
			num[Find(i)] ++;
		gn = 0;
		for (int i = 1; i <= n; ++ i)
			if (i != x && num[i] != 0) num[gn++] = num[i];
		//for (int i = 0; i < gn; ++ i)
		//	printf("%d ", num[i]);
		//puts("");
		memset(ans, 0, sizeof(ans));
		for (int i = 0; i < (1<<gn); ++ i)
		{
			int ts = nx;
			for (int j = 0; j < gn; ++ j)
				if (i&(1<<j)) ts += num[j];
			ans[ts] = 1;
		}
		for (int i = 1; i <= n; ++ i)
			if (ans[i]) printf("%d\n", i);
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 1005
int root[N];
void Init()
{
	for (int i = 0; i < N; ++ i)
		root[i] = i;
}
int Find(int x)
{
	if (root[x] != x) root[x] = Find(root[x]);
	return root[x];
}
void Merge(int x, int y)
{
	int fx = Find(x), fy = Find(y);
	if (fx != fy) root[fx] = fy;
}
int n, x, nx, an;
int num[N], gn;
bool vis[N], ans[N];
void dfs(int d, int sum, int ind)
{
	ans[sum+nx] = 1;
	if (d == gn) return ;
	for (int i = ind; i <= gn; ++ i) if (!vis[i] && (vis[i-1]||num[i]!=num[i-1]))
	{
		vis[i] = 1;
		dfs(d+1, sum+num[i], ind+1);
		vis[i] = 0;
	}
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	while (scanf("%d%d",&n,&x) != EOF)
	{
		Init();
		memset(num, 0, sizeof(num));
		for (int i=1,a; i <= n; ++ i)
		{
			scanf("%d", &a);
			if (a!=0) root[i] = a;
		}
		nx = 1;
		while (root[x] != x)
		{
			nx ++;
			x = root[x];
		}
		for (int i = 1; i <= n; ++ i)
			num[Find(i)] ++;
		num[gn=0] = 0;
		for (int i = 1; i <= n; ++ i)
			if (i != x && num[i] != 0) num[++gn] = num[i];
		sort(num+1, num+gn+1);
		memset(vis, 0, sizeof(vis));
		memset(ans, 0, sizeof(ans));
		dfs(0,0,1);
		an = 0;
		for (int i = 1; i <= n; ++ i)
			if (ans[i]) printf("%d\n", i);
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 1005
int root[N];
void Init()
{
	for (int i = 0; i < N; ++ i)
		root[i] = i;
}
int Find(int x)
{
	if (root[x] != x) root[x] = Find(root[x]);
	return root[x];
}
void Merge(int x, int y)
{
	int fx = Find(x), fy = Find(y);
	if (fx != fy) root[fx] = fy;
}
int n, x, nx, an;
int num[N], gn;
bool vis[N], ans[N];
void dfs(int d, int sum)
{
	ans[sum+nx] = 1;
	if (d == gn) return ;
	for (int i = 1; i <= gn; ++ i) if (!vis[i] && (vis[i-1]||num[i]!=num[i-1]))
	{
		vis[i] = 1;
		dfs(d+1, sum+num[i]);
		vis[i] = 0;
	}
}
int main()
{
	while (scanf("%d%d",&n,&x) != EOF)
	{
		Init();
		memset(num, 0, sizeof(num));
		for (int i=1,a; i <= n; ++ i)
		{
			scanf("%d", &a);
			if (a!=0) root[i] = a;
		}
		nx = 1;
		while (root[x] != x)
		{
			nx ++;
			x = root[x];
		}
		for (int i = 1; i <= n; ++ i)
			num[Find(i)] ++;
		num[gn=0] = 0;
		for (int i = 1; i <= n; ++ i)
			if (i != x && num[i] != 0) num[++gn] = num[i];
		sort(num+1, num+gn+1);
		memset(vis, 0, sizeof(vis));
		memset(ans, 0, sizeof(ans));
		dfs(0,0);
		an = 0;
		for (int i = 1; i <= n; ++ i)
			if (ans[i]) printf("%d\n", i);
	}
}


#ifdef WIN32
	#define I "%I64d"
		#else
	#define I "%lld"
#endif
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#include <windows.h>
#include <cmath>
#include <string>
#include <string.h>
#include <cstring>
#include <ctime>
#include <time.h>
#include <vector>
#include <map>
inline int Rand() {return (rand() << 16) | rand();}
inline int max(int x, int y) {return (x > y ? x : y);}
inline int min(int x, int y) {return (x < y ? x : y);}
#define y1 abcde
#define sqr(x) x * x
using namespace std;

const int N = 2000;
int n, i, l[N], r[N], a[N], m, p, x, j, pos;
bool was[N], used[N], w;

int go(int v)	{
	int u = v, kol = 0;
	w = false;
	while(l[u] != 0)	{
		kol++;
		u = l[u];
		was[u] = true;
		if (u == p){pos = kol + 1; w = true;}
	}
	if (p == v)	{w = true; pos = kol + 1;}
	u = v;
	while(r[u] != 0)	{
		kol++;
		u = r[u];
		was[u] = true;
        if (u == p){pos = kol + 1; w = true;}
	}
	return kol + 1;
}

int main()	{
	srand(GetTickCount());
	#ifndef ONLINE_JUDGE
	freopen("a.in", "r" , stdin);
	freopen("a.out", "w", stdout);
	#endif

	scanf("%d%d", &n, &p);
	for (i = 1; i <= n; i++)	{
		scanf("%d", &x);
		if (x != 0)	{
			l[i] = x;
			r[x] = i;
		}
	}
	for (i = 1; i <= n; i++)
		if (!was[i])	{
			a[++m] = go(i);
			if (w) m--;
			was[i] = true;
		}
	used[0] = true;
	for (i = 1; i <= m; i++)
		for (j = n; j >= 0; j--)
			if (used[j])	{
				used[j + a[i]] = true;
			}
	for (j = 0; j <= n; j++)
		if (used[j])
			printf("%d\n", j + pos);

	return 0;
}


#ifdef WIN32
	#define I "%I64d"
		#else
	#define I "%lld"
#endif
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#include <windows.h>
#include <cmath>
#include <string>
#include <string.h>
#include <cstring>
#include <ctime>
#include <time.h>
#include <vector>
#include <map>
inline int Rand() {return (rand() << 16) | rand();}
inline int max(int x, int y) {return (x > y ? x : y);}
inline int min(int x, int y) {return (x < y ? x : y);}
#define y1 abcde
#define sqr(x) x * x
using namespace std;

const int N = 2000;
int n, i, l[N], r[N], a[N], m, p, x, j, pos;
bool was[N], used[N];

int go(int v)	{
	int u = v, kol = 0;
	bool w = false;
	while(l[u] != 0)	{
		kol++;
		u = l[u];
		was[u] = true;
		if (u == p){pos = kol + 1; w = true;}
	}
	if (p == v)	{w = true; pos = kol + 1;}
	u = v;
	while(r[u] != 0)	{
		kol++;
		u = r[u];
		was[u] = true;
        if (u == p){pos = kol + 1; w = true;}
	}
	if (w) m--;
	return kol + 1;
}

int main()	{
	srand(GetTickCount());
	#ifndef ONLINE_JUDGE
	freopen("a.in", "r" , stdin);
	freopen("a.out", "w", stdout);
	#endif

	scanf("%d%d", &n, &p);
	for (i = 1; i <= n; i++)	{
		scanf("%d", &x);
		if (x != 0)	{
			l[i] = x;
			r[x] = i;
		}
	}
	for (i = 1; i <= n; i++)
		if (!was[i])	{
			a[++m] = go(i);
			was[i] = true;
		}
	used[0] = true;
	for (i = 1; i <= m; i++)
		for (j = n; j >= 0; j--)
			if (used[j])	{
				used[j + a[i]] = true;
			}
	for (j = 0; j <= n; j++)
		if (used[j])
			printf("%d\n", j + pos);

	return 0;
}


#ifdef WIN32
	#define I "%I64d"
		#else
	#define I "%lld"
#endif
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#include <windows.h>
#include <cmath>
#include <string>
#include <string.h>
#include <cstring>
#include <ctime>
#include <time.h>
#include <vector>
#include <map>
inline int Rand() {return (rand() << 16) | rand();}
inline int max(int x, int y) {return (x > y ? x : y);}
inline int min(int x, int y) {return (x < y ? x : y);}
#define y1 abcde
#define sqr(x) x * x
using namespace std;

const int N = 2000;
int n, i, l[N], r[N], a[N], m, p, x, j, pos;
bool was[N], used[N], w;

int go(int v)	{
	int u, kol = 0, z = 0;
	w = false;
	while(l[v] != 0)
        v = l[v];
    while(v != 0)    {
        was[v] = true;
        kol++;
        if (v == p) { pos = kol; w = true;}
        v = r[v];
    }
	return kol;
}

int main()	{
	srand(GetTickCount());
	#ifndef ONLINE_JUDGE
	freopen("a.in", "r" , stdin);
	freopen("a.out", "w", stdout);
	#endif

	scanf("%d%d", &n, &p);
	for (i = 1; i <= n; i++)	{
		scanf("%d", &x);
		if (x != 0)	{
			l[i] = x;
			r[x] = i;
		}
	}
	for (i = 1; i <= n; i++)
		if (!was[i])	{
			a[++m] = go(i);
			if (w) m--;
			was[i] = true;
		}
	used[0] = true;
	for (i = 1; i <= m; i++)
		for (j = n; j >= 0; j--)
			if (used[j])	{
				used[j + a[i]] = true;
			}
	for (j = 0; j <= n; j++)
		if (used[j])
			printf("%d\n", j + pos);

	return 0;
}


/**
 *@author A B M Faisal
 */

# include <iostream>
# include <sstream>

# include <vector>
# include <string>
# include <map>
# include <stack>
# include <queue>
# include <deque>
# include <set>
# include <algorithm>
# include <memory>

# include <utility>
# include <assert.h>

# include <cstring>
# include <cstdio>
# include <cctype>
# include <cstdlib>
# include <cmath>

using namespace std;
#define INF 0x7fffffff
#define X first
#define Y second
#define pb push_back
#define SZ(c) (int)(c).size()
#define MP make_pair
#define eps 1.0e-11
#define S(x) ((x)*(x))
#define I(n)   scanf("%d",&(n))

#define ALL(x) (x).begin(),(x).end()
#define SORT(c) sort(ALL(c))
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())

#define _(x) cout<<#x<<" => "<<x<<" "
#define _L(x) cout<<"Line : "<<__LINE__<<"    "<<#x<<" => "<<x<<endl
#define _V(x) { for(int i=0;i<(x).size();i++) cout<<#x<<"["<<i<<"] => "<<x[i]<<endl; cout<<endl;}
#define _A(x,N) { for(int i=0;i<(N);i++) cout<<#x<<"["<<i<<"] => "<<x[i]<<endl; cout<<endl;}
bool __insideGrid(int x,int y,int h,int w,int sx=0,int sy=0){
    if ( x < sx ) return false;
    if ( y < sy ) return false;
    if ( x >= sx+h ) return false;
    if ( y >= sy+w ) return false;
    return true;
}

const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,x;
    cin>>n>>x;

    vector<int> start;
    vector<int> after(n+1,-1),a(n+1);

    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if( a[i] == 0 ) start.push_back(i);
        else after [ a[i] ] = i;
    }

    vector<int> elem;
    int offset = -1;
    for(int i=0;i<start.size();i++)
    {
        int cnt=0;
        int cur = start[i];
        while( cur != -1 )
        {
            cnt++;
            if ( cur == x ){
                offset = cnt;
                break;
            }

            cur = after[cur];
        }
        if ( cur == -1 ) elem.push_back(cnt);
    }
    assert(offset!=-1);

    bool sum[1005]={0};
    sum[0]=1;
    for(int i=0;i<elem.size();i++)
    {
        for(int j=n;j>=elem[i];j--)
        {
            sum[j]=sum[j-elem[i]];
        }
    }

    for(int i=0;i<=n;i++)
    {
        if ( sum[i] )
            cout<<i+offset<<endl;
    }
    return 0;
}


/**
 *@author A B M Faisal
 */

# include <iostream>
# include <sstream>

# include <vector>
# include <string>
# include <map>
# include <stack>
# include <queue>
# include <deque>
# include <set>
# include <algorithm>
# include <memory>

# include <utility>
# include <assert.h>

# include <cstring>
# include <cstdio>
# include <cctype>
# include <cstdlib>
# include <cmath>

using namespace std;
#define INF 0x7fffffff
#define X first
#define Y second
#define pb push_back
#define SZ(c) (int)(c).size()
#define MP make_pair
#define eps 1.0e-11
#define S(x) ((x)*(x))
#define I(n)   scanf("%d",&(n))

#define ALL(x) (x).begin(),(x).end()
#define SORT(c) sort(ALL(c))
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())

#define _(x) cout<<#x<<" => "<<x<<" "
#define _L(x) cout<<"Line : "<<__LINE__<<"    "<<#x<<" => "<<x<<endl
#define _V(x) { for(int i=0;i<(x).size();i++) cout<<#x<<"["<<i<<"] => "<<x[i]<<endl; cout<<endl;}
#define _A(x,N) { for(int i=0;i<(N);i++) cout<<#x<<"["<<i<<"] => "<<x[i]<<endl; cout<<endl;}
bool __insideGrid(int x,int y,int h,int w,int sx=0,int sy=0){
    if ( x < sx ) return false;
    if ( y < sy ) return false;
    if ( x >= sx+h ) return false;
    if ( y >= sy+w ) return false;
    return true;
}

const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,x;
    cin>>n>>x;

    vector<int> start;
    vector<int> after(n+1,-1),a(n+1);

    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if( a[i] == 0 ) start.push_back(i);
        else after [ a[i] ] = i;
    }

    vector<int> elem;
    int offset = -1;

    for(int i=0;i<start.size();i++)
    {
        int cnt=0;
        int cur = start[i];
        while( cur != -1 )
        {
            cnt++;
            if ( cur == x ){
                offset = cnt;
                break;
            }

            cur = after[cur];
        }
        if ( cur == -1 ) elem.push_back(cnt);
    }
    assert(offset!=-1);

    vector<int> ans;
    for(int i=0;i<(1<<elem.size());i++)
    {
        int s =0 ;
        for(int j=0;j<elem.size();j++)
        {
            if ( i&(1<<j) ) s+= elem[j];
        }
        ans.push_back(s);
    }
    UNIQUE(ans);
    for(int i=0;i<ans.size();i++)
    {
        cout<<ans[i]+offset<<endl;
    }

    /*bool sum[1005]={0};
    sum[0]=1;
    for(int i=0;i<elem.size();i++)
    {
        for(int j=n;j>=elem[i];j--)
        {
            sum[j]=sum[j-elem[i]];
        }
    }

    for(int i=0;i<=n;i++)
    {
        if ( sum[i] )
            cout<<i+offset<<endl;
    }*/
    return 0;
}


/**
 *@author A B M Faisal
 */

# include <iostream>
# include <sstream>

# include <vector>
# include <string>
# include <map>
# include <stack>
# include <queue>
# include <deque>
# include <set>
# include <algorithm>
# include <memory>

# include <utility>
# include <assert.h>

# include <cstring>
# include <cstdio>
# include <cctype>
# include <cstdlib>
# include <cmath>

using namespace std;
#define INF 0x7fffffff
#define X first
#define Y second
#define pb push_back
#define SZ(c) (int)(c).size()
#define MP make_pair
#define eps 1.0e-11
#define S(x) ((x)*(x))
#define I(n)   scanf("%d",&(n))

#define ALL(x) (x).begin(),(x).end()
#define SORT(c) sort(ALL(c))
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())

#define _(x) cout<<#x<<" => "<<x<<" "
#define _L(x) cout<<"Line : "<<__LINE__<<"    "<<#x<<" => "<<x<<endl
#define _V(x) { for(int i=0;i<(x).size();i++) cout<<#x<<"["<<i<<"] => "<<x[i]<<endl; cout<<endl;}
#define _A(x,N) { for(int i=0;i<(N);i++) cout<<#x<<"["<<i<<"] => "<<x[i]<<endl; cout<<endl;}
bool __insideGrid(int x,int y,int h,int w,int sx=0,int sy=0){
    if ( x < sx ) return false;
    if ( y < sy ) return false;
    if ( x >= sx+h ) return false;
    if ( y >= sy+w ) return false;
    return true;
}

const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,x;
    cin>>n>>x;

    int after[1005]={0};
    int data[1005]={0};
    vector<int> st;

    for(int i=0;i<n;i++)
    {
        cin>>data[i+1];
        if ( data[i+1] == 0 ) st.push_back(i+1);
        after[data[i+1]]=i+1;
    }

    vector<int> elem;
    int offset;
    for(int i=0;i<st.size();i++)
    {
        int size=0;

        int cur= st[i];

        while( cur )
        {
            size++;
            if( cur == x ){
                    offset = size;
                    break;
            }
            cur = after[cur];
        }

        if (!cur)
            elem.push_back(size);
    }

    bool sum[1005]={0};
    sum[0]=1;
    for(int i=0;i<elem.size();i++)
    {
        for(int j=n;j>=elem[i];j--)
        {
            sum[j]=sum[j-elem[i]];
        }
    }

    for(int i=0;i<=n;i++)
    {
        if ( sum[i] )
            cout<<i+offset<<endl;
    }
    return 0;
}


# include<cstdio>
# include<cstring>
# include<algorithm>
# include<map>
using namespace std;

# define N 1005
bool vis[N],flag;
int f[N],v;
int pre[N],Next[N],n,m;
map<int,int> imap;
map<int,int>::iterator it;

int getpre(int x)
{
    int res=0;
    while(pre[x]!=-1)
    {
        res++;
        vis[x]=1;
        if(x==m)
            flag=1;
        x=pre[x];
    }
    vis[x]=1;
    if(x==m)
        flag=1;
    return res;
}

int getnext(int x)
{
    int res=0;
    while(Next[x]!=-1)
    {
        res++;
        vis[x]=1;
        if(x==m)
            flag=1;
        x=Next[x];
    }
    vis[x]=1;
    if(x==m)
        flag=1;
    return res;
}

void pack01(int w)
{
    int i;
    for(i=v;i>=w;i--)
        f[i]+=f[i-w];
}

void allpack(int w)
{
    int i;
    for(i=w;i<=v;i++)
        f[i]+=f[i-w];
}

void mulpack(int w,int c)
{
    int i;
    if(w*c>=v)
        allpack(w);
    for(i=1;i<c;i*=2)
    {
        pack01(i*w);
        c-=i;
    }
    pack01(c*w);
}

int main()
{
    int i,x,sure,nosure;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        v=n;
        memset(f,0,sizeof(f));
        f[0]=1;

        imap.clear();
        sure=nosure=0;  //
        memset(vis,0,sizeof(vis));
        memset(pre,-1,sizeof(pre));
        memset(Next,-1,sizeof(Next));
        for(i=1;i<=n;i++)
        {
            scanf("%d",&x);
            if(x)
            {
                Next[x]=i;
                pre[i]=x;
            }
        }
        for(i=1;i<=n;i++)
            if(!vis[i])
            {
                flag=0;
                int c=getpre(i)+getnext(i)+1;
            //  printf("%d:%d\n",i,c);
                if(c>1&&!flag)
                    imap[c]++,sure+=c;
            }
        int tmp=getpre(m)+getnext(m)+1;
        nosure=n-sure-tmp;

        imap[1]=nosure;
        int minpos=getpre(m)+1;
    //  printf("minpos=%d sure=%d nosure=%d\n",minpos,sure,nosure);
        for(it=imap.begin();it!=imap.end();it++)
            mulpack(it->first,it->second);
        for(i=0;i<=n;i++)
            if(f[i])
                printf("%d\n",i+minpos);
    }
    return 0;
}
/*
6 1
2 0 4 0 6 0
6 2
2 3 0 5 6 0
4 1
0 0 0 0
6 2
0 0 1 0 4 5
6 2
0 0 1 0 4 5
*/


# include<cstdio>
# include<cstring>
# include<algorithm>
using namespace std;

# define N 1005

int n,m;
int pre[N],dep[N],d[N],f[N],pos;
bool flag,vis[N];

void dfs(int u)
{
    if(u==0)
        return;
    dfs(pre[u]);
    dep[u]=dep[pre[u]]+1;
    if(u==m)
    {
        pos=dep[u];
        flag=1;
    }
}

int main()
{
    int i,j,x,num;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        num=0;
        memset(vis,0,sizeof(vis));
        memset(pre,0,sizeof(pre));
        memset(f,0,sizeof(f));
        f[0]=1;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&x);
            pre[i]=x;
            vis[x]=1;
        }
        for(i=1;i<=n;i++)
            if(!vis[i])
            {
                flag=0;
                dfs(i);
                if(!flag)
                    d[num++]=dep[i];
            }
        memset(f,0,sizeof(f));
        f[0]=1;
        for(i=0;i<num;i++)
        {
            int w=d[i];
            for(j=n-w;j>=0;j--)
                if(f[j])
                    f[j+w]=1;
        }
        for(i=0;i<n;i++)
            if(f[i])
                printf("%d\n",pos+i);
    }
    return 0;
}