import java.util.*;
public class Test {

	public static void zero() {
		System.out.println("1");
		System.out.println("0");
	}
	public static void one() {
		System.out.println("2");
		System.out.println("1 1");
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-- != 0) {
			int n = sc.nextInt();
			int a[] = new int[n];
			for(int i = 0;i<n;i++) a[i] = sc.nextInt();

			int one = 0;
			int zero = 0;
			int flag = 5;
			int sum =0;
			for(int i = 0;i<n;i++) sum += a[i];

			if(n == 2 && sum == 0) {
				zero();
				continue;
			}
			if(n == 2 && sum == 1) {
				zero();
				continue;
			}
			if(n == 2 && sum == 2) {
				one();
				continue;
			}

			if(a[0] == 1) {
				one++;
			}
			else zero++;

			for(int i = 1;i<n;i++) {
				if(a[i] == 1 && a[i-1] == 1) {
					one++;
				}
				else if(a[i] == 0 && a[i-1] == 0) zero++;
				if(one >= n/2) {
					flag = 1;
					break;
				}
				if(zero >= n/2) {
					flag = 0;
					break;
				}
				if(one + zero >= n/2 && one > 1 && zero > 1) {
					flag = 2;
					break;
				}
			}

//
//
//				if(one >= n/2) {
//					flag = 1;
//					break;
//				}
//				if(zero >= n/2) {
//					flag = 0;
//					break;
//				}
//

//			int res[] = new int[n];
//			Arrays.fill(res, -1);
//			if(one == zero) {
//				for(int i = 0;i<one;i++)
//			}

			if(flag == 0) {
				System.out.println(zero);
				for(int i = 0;i<zero;i++) {
					if(i != n-1) System.out.print("0 ");
					else System.out.print("0");
				}
			}

			if(flag == 1) {
				System.out.println(one);
				for(int i = 0;i<one;i++) {
					if(i != n-1)
					System.out.print("1 ");
					else System.out.print("1");
				}
			}

			if(flag == 2) {
				System.out.println(one + zero);
				for(int i = 0;i<one;i++) {
					System.out.print("1 ");
				}
				for(int i = 0;i<zero;i++) {
					if(i != zero-1)
					System.out.print("0 ");
					else System.out.println("0");
				}

			}
			System.out.println();
		}
	}

}


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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T;
    cin>>T;
    for(;T>0;T--){
        int n;
        cin >> n;
        cout << max(0,n - 2) << "\n";
    }
    return 0;
}


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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T;
    cin>>T;
    for(;T>0;T--){
        int n;
        cin >> n;
        cout << n - 2;
    }
    return 0;
}


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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T;
    cin>>T;
    for(;T>0;T--){
        int n;
        cin >> n;
        cout << n - 2 << "\n";
    }
    return 0;
}


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

int main(){

	int t=0, n=0;
	cin >> t;

	while(t--){
		cin >> n;
		if(n-2<1){
            cout << 0 << '\n';
        }else{
            cout << n-2 << '\n';
        }
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int frr[111];
int root (int r ) {
    while (r != frr[r]) {
        frr[r] = frr[frr[r]];
        r = frr[r];
    }
    return r;
}
int main() {
    int  tt;
    cin >> tt;
    while (tt--) {
        int n;
        cin >> n;
        if (n == 1) cout << 0 << '\n';
        else if (n <= 3) cout << 1 << '\n';
        else cout << n - 1 << '\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
int frr[111];
int root (int r ) {
    while (r != frr[r]) {
        frr[r] = frr[frr[r]];
        r = frr[r];
    }
    return r;
}
int main() {
    int  tt;
    cin >> tt;
    while (tt--) {
        int n;
        cin >> n;
        if (n == 1) cout << 0 << '\n';
        else if (n <= 3) cout << 1 << '\n';
        else cout << n - 2 << '\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
int frr[111];
int root (int r ) {
    while (r != frr[r]) {
        frr[r] = frr[frr[r]];
        r = frr[r];
    }
    return r;
}
int main() {
    int  tt;
    cin >> tt;
    while (tt--) {
        int n;
        cin >> n;
        if (n == 1 || n == 2) cout << 0 << '\n';
        else if (n <= 3) cout << 1 << '\n';
        else cout << n - 2 << '\n';
    }
}


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

const int N = 2e5 + 5;
int n, t;

int main() {
    cin >> t;
	while (t--) {
		cin >> n;
		if (n > 2) cout << n - 2 << endl;
		else cout << 0 << endl;
	}
}


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

int n, t;

int main() {
    cin >> t;
	while (t--) {
		cin >> n;
		cout << n - 2 << endl;
	}
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    for (int i = 0; i < t; i ++) {
        int n;
        cin >> n;
        int ret = n >= 2 ? n - 2 : 0;
        cout << ret << endl;
    }
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    for (int i = 0; i < t; i ++) {
        int n;
        cin >> n;
        ret = n >= 2 ? n - 2 : 0;
        cout << ret << endl;
    }
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; i ++) {
        int n;
        cin >> n;
        int ret = n >= 2 ? n - 2 : 0;
        cout << ret << endl;
    }
}


#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,n) for(int j=0;j<n;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef vector<pair<int, int> > vepa;
typedef set<int>se;
typedef map<ll,ll> mpp;
const ll N=1e6,OO=1e14,MOD=1e9+7;
const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};
ll TC,n,m,k,a,b,l,r,cnt,sum,mx,mn,arr[N],A[N],ans[N];
bool f,vis[N];
int main(){
    IOS;
    cin>>TC;
    while(TC--)
    {
        cin>>n;
        cout<<(n==1?0:n-2)<<"\n";
    }
go;
}


#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,n) for(int j=0;j<n;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef vector<pair<int, int> > vepa;
typedef set<int>se;
typedef map<ll,ll> mpp;
const ll N=1e6,OO=1e14,MOD=1e9+7;
const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};
ll TC,n,m,k,a,b,l,r,cnt,sum,mx,mn,arr[N],A[N],ans[N];
bool f,vis[N];
int main(){
    IOS;
    cin>>TC;
    while(TC--)
    {
        cin>>n;
        cout<<(n==1?0:n-2);
    }
go;
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        cout<<max(n-2,0)<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        cout<<n-2<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        cout<<n/3<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	ll t;
	cin >> t;

	while(t--)
	{
		ll n;
		cin >> n;

		cout << max((ll)0, n-2) << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	ll t;
	cin >> t;

	while(t--)
	{
		ll n;
		cin >> n;

		cout << max((ll)0, n-2);
	}

	return 0;
}


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

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		if(n==1) cout<<0<<endl;
		else cout<<n-2<<endl;
	}
}


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

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		if(n==2) cout<<0<<endl;
		else cout<<n/2<<endl;
	}
}


#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define ll long long
#define pb(k) push_back(k)
#define mp(k,d) make_pair(k,d)
#define ts(k) to_string(k)
#define pii pair<int,int>
#define F first
#define S second
#define INF 1e9+7
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    while(n--){
        int t;
        cin>>t;
        if(t==2)cout<<0;
        else cout<<t/2<<endl;
    }
}


#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define ll long long
#define pb(k) push_back(k)
#define mp(k,d) make_pair(k,d)
#define ts(k) to_string(k)
#define pii pair<int,int>
#define F first
#define S second
#define INF 1e9+7
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    while(n--){
        int t;
        cin>>t;
        cout<<max(t-2,0)<<endl;
    }
}


#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define ll long long
#define pb(k) push_back(k)
#define mp(k,d) make_pair(k,d)
#define ts(k) to_string(k)
#define pii pair<int,int>
#define F first
#define S second
#define INF 1e9+7
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    while(n--){
        int t;
        cin>>t;
        cout<<(t-1)/2<<endl;
    }
}


#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define ll long long
#define pb(k) push_back(k)
#define mp(k,d) make_pair(k,d)
#define ts(k) to_string(k)
#define pii pair<int,int>
#define F first
#define S second
#define INF 1e9+7
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    while(n--){
        int t;
        cin>>t;
        cout<<t/3<<endl;
    }
}


#include<iostream>
#include<bits/stdc++.h>
typedef long long  ll;
typedef unsigned long long int _ll;
using namespace std;
#define INF          1LL<<62
#define mod          1000000007
#define mod1         998244353
#define N            300100
#define PI           3.14159265
#define faster       ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define pb           push_back
#define ppb          pop_back
#define endl         '\n'
#define mii          unordered_map<ll,ll>
#define mis          unordered_map<ll,string>
#define msi          unordered_map<string,ll>
#define rep(i,a,b)   for(ll i=a;i<b;i++)
#define pii          pair<ll,ll>
#define vi           vector<ll>
#define vs           vector<string>
#define all(a)       (a).begin(),(a).end()
#define F             first
#define S            second
/* ll  modExpo( ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
    return modExpo((x*x)%mod1,n/2);
    else
    return (x*modExpo((x*x)%mod1,(n-1)/2))%mod1;
}
ll modInverse(ll n)
{
    return modExpo(n,mod1-2);
} */

int  main()
{
  int t;
  cin>>t;
  while(t--)
  {
    int k;
    cin>>k;
    if(k<=2)
        cout<<0<<endl;
    else
    cout<<k-2<<endl;
  }

}


#include<iostream>
#include<bits/stdc++.h>
typedef long long  ll;
typedef unsigned long long int _ll;
using namespace std;
#define INF          1LL<<62
#define mod          1000000007
#define mod1         998244353
#define N            300100
#define PI           3.14159265
#define faster       ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define pb           push_back
#define ppb          pop_back
#define endl         '\n'
#define mii          unordered_map<ll,ll>
#define mis          unordered_map<ll,string>
#define msi          unordered_map<string,ll>
#define rep(i,a,b)   for(ll i=a;i<b;i++)
#define pii          pair<ll,ll>
#define vi           vector<ll>
#define vs           vector<string>
#define all(a)       (a).begin(),(a).end()
#define F             first
#define S            second
/* ll  modExpo( ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
    return modExpo((x*x)%mod1,n/2);
    else
    return (x*modExpo((x*x)%mod1,(n-1)/2))%mod1;
}
ll modInverse(ll n)
{
    return modExpo(n,mod1-2);
} */

int  main()
{
  int t;
  cin>>t;
  while(t--)
  {
    int k;
    cin>>k;
    cout<<k/2<<endl;
  }

}


#include<iostream>
#include<bits/stdc++.h>
typedef long long  ll;
typedef unsigned long long int _ll;
using namespace std;
#define INF          1LL<<62
#define mod          1000000007
#define mod1         998244353
#define N            300100
#define PI           3.14159265
#define faster       ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define pb           push_back
#define ppb          pop_back
#define endl         '\n'
#define mii          unordered_map<ll,ll>
#define mis          unordered_map<ll,string>
#define msi          unordered_map<string,ll>
#define rep(i,a,b)   for(ll i=a;i<b;i++)
#define pii          pair<ll,ll>
#define vi           vector<ll>
#define vs           vector<string>
#define all(a)       (a).begin(),(a).end()
#define F             first
#define S            second
/* ll  modExpo( ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
    return modExpo((x*x)%mod1,n/2);
    else
    return (x*modExpo((x*x)%mod1,(n-1)/2))%mod1;
}
ll modInverse(ll n)
{
    return modExpo(n,mod1-2);
} */

int  main()
{
  int t;
  cin>>t;
  while(t--)
  {
    int k;
    cin>>k;
    cout<<k-2<<endl;
  }

}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
//#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007 //998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 100000000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
void solve()
{  int n;
   cin>>n;
   cout<<(n+2)/3<<endl;
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int t;
   cin>>t;
   while(t--)
   {
       solve();
   }
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
//#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007 //998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 100000000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
void solve()
{  int n;
   cin>>n;
   cout<<max(0LL,(n-2))<<endl;
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int t;
   cin>>t;
   while(t--)
   {
       solve();
   }
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
//#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007 //998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 100000000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
void solve()
{  int n;
   cin>>n;
   cout<<(n-2)<<endl;
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int t;
   cin>>t;
   while(t--)
   {
       solve();
   }
}


/*  Praney Rai
  IIT(ISM) Dhanbad */

// Welcome ;)

#include <stdio.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define loop(i,a,b) for(ll i=(a); i<(b); i++)
#define rep(i, b) for(ll i=(0); i<(b); i++)
#define rep1(i, b) for (ll i=1; i<b; i++)
#define rrep(i, n) for(ll i=(n-1); i>=0; i--)
#define rloop(i,a,b) for(ll i=(b-1);i>=a;i--)
#define loopi(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define apac freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fill(a,v)	memset(a, v, sizeof(a))
#define si(n)	scanf("%lld",&n)
#define sc(n)   scanf("%c",&n)
#define sd(n)   scanf("%lf",&n)
#define pln(x) 	printf("%lld\n", x)
#define pr(x) 	printf("%lld ", x)
#define nl	printf("\n")
#define all(x) x.begin(), x.end()
#define remax(a,b) (a)=max((a),(b));
#define remin(a,b) (a)=min((a),(b));
#define xx first
#define yy second
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define rtn return
#define exit exit(0)
#define sz(x) ((ll)(x).size())
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define Mid(s,e) (s+(e-s)/2)
#define Abs(a, b)	Max(a-b,b-a)
#define kuch cout << "kuch bhi\n"
#define debug(x) cout << #x << ": " << x << "\n"
#define fout(a, b) cout << fixed << setprecision((b)) << (a)
#ifdef _WIN32
	#define pc putchar
	#define gc getchar
#else
	#define pc putchar_unlocked
	#define gc getchar_unlocked
#endif

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef std::string str;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vi> MATRIX;

//const. list--->>>
const int MOD7 = int(1e9) + 7;
const int MOD9 = int(1e9) + 9;
const db Pi = 3.1415926535897932384626433832795;
const db eps = 0.000000001;
const ll Inf = 0x7FFFFFFFFFFFFFFF;

/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction

//Fast-I/O--->>>
inline str sin() {str s=""; while (1) {char c = gc(); if(c==' '|| c=='\n') break; s += c; } rtn s;}
inline ll in() {int n=0; ll x=0; char c = gc(); if(c == '-') n=1; while (c < '0' || c > '9') {c=gc(); if (c == '-') n = 1; }
	while (c >= '0' && c <= '9') {x = (x << 3) + (x << 1) + c - '0'; c = gc();} if (n) x = -x; rtn x;}
inline void put (ll a) {int n = (a < 0 ? 1 : 0); if (n) a = -a; char b[20]; int i = 0; do {b[i++] = a % 10 + '0'; a /= 10;}
	while (a); if (n) pc('-'); i--; while (i >= 0) pc(b[i--]); pc(' ');}
inline void putln(ll a) {int n = (a < 0 ? 1 : 0); if(n) a = -a; char b[20]; int i = 0; do{b[i++] = a % 10 + '0'; a /= 10;}
	while (a); if (n) pc('-'); i--; while (i >= 0) pc(b[i--]); pc('\n');}

//Other Utilities--->>>
inline ll fmm (ll a, ll b, ll m = MOD7) {ll r = 0; a %= m; b %= m; while (b > 0) {if (b & 1) {r += a; r %= m;} a += a; a %= m; b >>= 1;}rtn r % m;}
inline ll fme (ll a, ll b, ll m = MOD7) {ll r = 1; a %= m; while (b > 0) {if (b & 1){r *= a; r %= m;} a *= a; a %= m; b >>= 1;} rtn r % m;}
inline ll sfme (ll a, ll b, ll m = MOD7) {ll r = 1; a %= m; while (b > 0) {if (b & 1) r = fmm(r, a, m); a = fmm(a, a, m); b >>= 1;} rtn r % m;}
// For primefactorization after sieve
/*
bool v[nu]; int sp[nu];
void Sieve() {for (ll i = 2; i < nu; i += 2) sp[i] = 2; for (ll i = 3; i < nu; i += 2){if (!v[i]){sp[i] = i;
	for (ll j = i; (j*i) < nu; j += 2){if (!v[j*i])	v[j*i] = true, sp[j*i] = i;}}}}
vi fctz(ll k) {vi ans; while(k>1) {ans.push_back(sp[k]); k /= sp[k];} rtn ans;}
/*ll fact[1000001], invfact[1000001];
inline void init (ll MOD = MOD7){ll i; fact[0] = 1; for (i = 1; i <= 1000000; i++) fact[i] = (fact[i - 1] * i) % MOD;
	invfact[1000000] = fme (fact[1000000], MOD - 2, MOD); for (i = 1000000 - 1; i >= 0; i--) invfact[i] = (invfact[i + 1] * (i + 1)) % MOD;}
inline ll nCk (ll n, ll k, ll MOD = MOD7){rtn (((fact[n] * invfact[k]) % MOD) * invfact[n - k]) % MOD;}
inline ll nPk (ll n, ll k, ll MOD = MOD7){rtn ((fact[n] * invfact[k]) % MOD);}*/
//nCk in O(k)
ll NCK (ll n, ll k, ll MOD = MOD7) {ll res = 1; if (k > n - k) k = n - k; rep (i, k) {res *= (n - i); res /= (i+1);} rtn res % MOD;}
template <class T> T gcd (T a, T b) {if (b == 0) rtn a; rtn gcd (b, a % b);}
inline void eGCD(ll a, ll b, ll &x, ll &y) {if (b == 0) {x = 1, y = 0; rtn;} ll x1, y1; eGCD (b, a % b, x1, y1); x = y1; y = x1 - (a / b) * y1;}
template <class T> T lcm(T a, T b){rtn (a * b) / gcd(a, b);}
inline MATRIX mul (MATRIX &A, MATRIX &B, ll m = MOD7) {ll n = A.size(), i , j, k; MATRIX C(n, vector<ll>(n));
	for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % m; rtn C;}
inline MATRIX Mpow (MATRIX &A, ll x, ll m = MOD7) {ll n = A.size(), i; MATRIX B(n, vi(n)); for (i = 0; i < n; i++) B[i][i] = 1;
	while (x > 0) {if (x % 2) B = mul (B, A, m); x /= 2; A = mul (A, A, m);} rtn B;}
inline bool isSub (str &txt, str &s) {int pos = -1; bool ok = true; for (int i = 0; ok && i!=s.size(); i++) {ok = (pos = txt.find(s[i], pos+1)) != string::npos;} rtn ok;}
inline int countOne (ll n) {int count = 0; while (n) {n = n & (n-1); count++;} rtn count;}
inline str srev (str &s){str demo = ""; for (int i = s.length() - 1; i >= 0; i--) demo += s[i]; rtn demo;}
inline str tb (ll i) {str ans = ""; str arr = "01"; while (i) {ans += arr[i%2]; i = i / 2;} rtn srev(ans);}
inline ll maxSub (ll a[],ll n) {ll e = -Inf, s = 0; rep (i, n) {s += a[i]; if (e < s) e = s; if (s < 0) s = 0;} rtn e;}
inline ll minSub (ll a[],ll n) {ll e = Inf, s = 0; rep (i, n) {s += a[i]; if (e > s) e = s; if(s > 0) s = 0;} rtn e;}
template<class T> inline T Pow(T a, ll b){T c(1); while (b) {if (b & 1) c *= a; a *= a, b >>= 1;} rtn c;}
inline ll pp(int x) {ll r = 1; rep (i, x) r = r * 2LL; rtn r;}
//seive of Eratosthenes(prime's marked with 0)
/*ll isPrime[1000100];
void pinit() {isPrime[0] = 1, isPrime[1] = 1; for (ll i = 2; i * i <= 1000100; i++) {if (!isPrime[i]) {for (ll j = i*i; j < 1000100; j += i) isPrime[j] = 1;}}}*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const ll nu = 100100;

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	ll n = 0, m = 0, k = 0, lo = 0, hi = 0, mi = Inf, mx = -Inf, sum = 0, ans = 0, cnt=0, t = 0, v1 = 0, v2 = 0, x1 = 0, x2 = 0, x3 = 0, y1 = 0, y2 = 0, y3 = 0, curr = 0,
	q = 0, x = 0, y = 0, p = 0;
	str s, s1, s2;
	char c, c1, c2, *ptr;
	bool ok, okay;
	db dub=0;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//start here
	cin >> t;
	while(t--) {
		cin >> n;
		if (n == 3) cout << 1 << endl;
		else cout << 2 << endl;
	}

}


/*  Praney Rai
  IIT(ISM) Dhanbad */

// Welcome ;)

#include <stdio.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define loop(i,a,b) for(ll i=(a); i<(b); i++)
#define rep(i, b) for(ll i=(0); i<(b); i++)
#define rep1(i, b) for (ll i=1; i<b; i++)
#define rrep(i, n) for(ll i=(n-1); i>=0; i--)
#define rloop(i,a,b) for(ll i=(b-1);i>=a;i--)
#define loopi(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define apac freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fill(a,v)	memset(a, v, sizeof(a))
#define si(n)	scanf("%lld",&n)
#define sc(n)   scanf("%c",&n)
#define sd(n)   scanf("%lf",&n)
#define pln(x) 	printf("%lld\n", x)
#define pr(x) 	printf("%lld ", x)
#define nl	printf("\n")
#define all(x) x.begin(), x.end()
#define remax(a,b) (a)=max((a),(b));
#define remin(a,b) (a)=min((a),(b));
#define xx first
#define yy second
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define rtn return
#define exit exit(0)
#define sz(x) ((ll)(x).size())
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define Mid(s,e) (s+(e-s)/2)
#define Abs(a, b)	Max(a-b,b-a)
#define kuch cout << "kuch bhi\n"
#define debug(x) cout << #x << ": " << x << "\n"
#define fout(a, b) cout << fixed << setprecision((b)) << (a)
#ifdef _WIN32
	#define pc putchar
	#define gc getchar
#else
	#define pc putchar_unlocked
	#define gc getchar_unlocked
#endif

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef std::string str;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vi> MATRIX;

//const. list--->>>
const int MOD7 = int(1e9) + 7;
const int MOD9 = int(1e9) + 9;
const db Pi = 3.1415926535897932384626433832795;
const db eps = 0.000000001;
const ll Inf = 0x7FFFFFFFFFFFFFFF;

/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction

//Fast-I/O--->>>
inline str sin() {str s=""; while (1) {char c = gc(); if(c==' '|| c=='\n') break; s += c; } rtn s;}
inline ll in() {int n=0; ll x=0; char c = gc(); if(c == '-') n=1; while (c < '0' || c > '9') {c=gc(); if (c == '-') n = 1; }
	while (c >= '0' && c <= '9') {x = (x << 3) + (x << 1) + c - '0'; c = gc();} if (n) x = -x; rtn x;}
inline void put (ll a) {int n = (a < 0 ? 1 : 0); if (n) a = -a; char b[20]; int i = 0; do {b[i++] = a % 10 + '0'; a /= 10;}
	while (a); if (n) pc('-'); i--; while (i >= 0) pc(b[i--]); pc(' ');}
inline void putln(ll a) {int n = (a < 0 ? 1 : 0); if(n) a = -a; char b[20]; int i = 0; do{b[i++] = a % 10 + '0'; a /= 10;}
	while (a); if (n) pc('-'); i--; while (i >= 0) pc(b[i--]); pc('\n');}

//Other Utilities--->>>
inline ll fmm (ll a, ll b, ll m = MOD7) {ll r = 0; a %= m; b %= m; while (b > 0) {if (b & 1) {r += a; r %= m;} a += a; a %= m; b >>= 1;}rtn r % m;}
inline ll fme (ll a, ll b, ll m = MOD7) {ll r = 1; a %= m; while (b > 0) {if (b & 1){r *= a; r %= m;} a *= a; a %= m; b >>= 1;} rtn r % m;}
inline ll sfme (ll a, ll b, ll m = MOD7) {ll r = 1; a %= m; while (b > 0) {if (b & 1) r = fmm(r, a, m); a = fmm(a, a, m); b >>= 1;} rtn r % m;}
// For primefactorization after sieve
/*
bool v[nu]; int sp[nu];
void Sieve() {for (ll i = 2; i < nu; i += 2) sp[i] = 2; for (ll i = 3; i < nu; i += 2){if (!v[i]){sp[i] = i;
	for (ll j = i; (j*i) < nu; j += 2){if (!v[j*i])	v[j*i] = true, sp[j*i] = i;}}}}
vi fctz(ll k) {vi ans; while(k>1) {ans.push_back(sp[k]); k /= sp[k];} rtn ans;}
/*ll fact[1000001], invfact[1000001];
inline void init (ll MOD = MOD7){ll i; fact[0] = 1; for (i = 1; i <= 1000000; i++) fact[i] = (fact[i - 1] * i) % MOD;
	invfact[1000000] = fme (fact[1000000], MOD - 2, MOD); for (i = 1000000 - 1; i >= 0; i--) invfact[i] = (invfact[i + 1] * (i + 1)) % MOD;}
inline ll nCk (ll n, ll k, ll MOD = MOD7){rtn (((fact[n] * invfact[k]) % MOD) * invfact[n - k]) % MOD;}
inline ll nPk (ll n, ll k, ll MOD = MOD7){rtn ((fact[n] * invfact[k]) % MOD);}*/
//nCk in O(k)
ll NCK (ll n, ll k, ll MOD = MOD7) {ll res = 1; if (k > n - k) k = n - k; rep (i, k) {res *= (n - i); res /= (i+1);} rtn res % MOD;}
template <class T> T gcd (T a, T b) {if (b == 0) rtn a; rtn gcd (b, a % b);}
inline void eGCD(ll a, ll b, ll &x, ll &y) {if (b == 0) {x = 1, y = 0; rtn;} ll x1, y1; eGCD (b, a % b, x1, y1); x = y1; y = x1 - (a / b) * y1;}
template <class T> T lcm(T a, T b){rtn (a * b) / gcd(a, b);}
inline MATRIX mul (MATRIX &A, MATRIX &B, ll m = MOD7) {ll n = A.size(), i , j, k; MATRIX C(n, vector<ll>(n));
	for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % m; rtn C;}
inline MATRIX Mpow (MATRIX &A, ll x, ll m = MOD7) {ll n = A.size(), i; MATRIX B(n, vi(n)); for (i = 0; i < n; i++) B[i][i] = 1;
	while (x > 0) {if (x % 2) B = mul (B, A, m); x /= 2; A = mul (A, A, m);} rtn B;}
inline bool isSub (str &txt, str &s) {int pos = -1; bool ok = true; for (int i = 0; ok && i!=s.size(); i++) {ok = (pos = txt.find(s[i], pos+1)) != string::npos;} rtn ok;}
inline int countOne (ll n) {int count = 0; while (n) {n = n & (n-1); count++;} rtn count;}
inline str srev (str &s){str demo = ""; for (int i = s.length() - 1; i >= 0; i--) demo += s[i]; rtn demo;}
inline str tb (ll i) {str ans = ""; str arr = "01"; while (i) {ans += arr[i%2]; i = i / 2;} rtn srev(ans);}
inline ll maxSub (ll a[],ll n) {ll e = -Inf, s = 0; rep (i, n) {s += a[i]; if (e < s) e = s; if (s < 0) s = 0;} rtn e;}
inline ll minSub (ll a[],ll n) {ll e = Inf, s = 0; rep (i, n) {s += a[i]; if (e > s) e = s; if(s > 0) s = 0;} rtn e;}
template<class T> inline T Pow(T a, ll b){T c(1); while (b) {if (b & 1) c *= a; a *= a, b >>= 1;} rtn c;}
inline ll pp(int x) {ll r = 1; rep (i, x) r = r * 2LL; rtn r;}
//seive of Eratosthenes(prime's marked with 0)
/*ll isPrime[1000100];
void pinit() {isPrime[0] = 1, isPrime[1] = 1; for (ll i = 2; i * i <= 1000100; i++) {if (!isPrime[i]) {for (ll j = i*i; j < 1000100; j += i) isPrime[j] = 1;}}}*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const ll nu = 100100;

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	ll n = 0, m = 0, k = 0, lo = 0, hi = 0, mi = Inf, mx = -Inf, sum = 0, ans = 0, cnt=0, t = 0, v1 = 0, v2 = 0, x1 = 0, x2 = 0, x3 = 0, y1 = 0, y2 = 0, y3 = 0, curr = 0,
	q = 0, x = 0, y = 0, p = 0;
	str s, s1, s2;
	char c, c1, c2, *ptr;
	bool ok, okay;
	db dub=0;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//start here
	cin >> t;
	while(t--) {
		cin >> n;
		cout << max(0LL, n-2) << endl;
	}

}


/*  Praney Rai
  IIT(ISM) Dhanbad */

// Welcome ;)

#include <stdio.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define loop(i,a,b) for(ll i=(a); i<(b); i++)
#define rep(i, b) for(ll i=(0); i<(b); i++)
#define rep1(i, b) for (ll i=1; i<b; i++)
#define rrep(i, n) for(ll i=(n-1); i>=0; i--)
#define rloop(i,a,b) for(ll i=(b-1);i>=a;i--)
#define loopi(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define apac freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fill(a,v)	memset(a, v, sizeof(a))
#define si(n)	scanf("%lld",&n)
#define sc(n)   scanf("%c",&n)
#define sd(n)   scanf("%lf",&n)
#define pln(x) 	printf("%lld\n", x)
#define pr(x) 	printf("%lld ", x)
#define nl	printf("\n")
#define all(x) x.begin(), x.end()
#define remax(a,b) (a)=max((a),(b));
#define remin(a,b) (a)=min((a),(b));
#define xx first
#define yy second
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define rtn return
#define exit exit(0)
#define sz(x) ((ll)(x).size())
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define Mid(s,e) (s+(e-s)/2)
#define Abs(a, b)	Max(a-b,b-a)
#define kuch cout << "kuch bhi\n"
#define debug(x) cout << #x << ": " << x << "\n"
#define fout(a, b) cout << fixed << setprecision((b)) << (a)
#ifdef _WIN32
	#define pc putchar
	#define gc getchar
#else
	#define pc putchar_unlocked
	#define gc getchar_unlocked
#endif

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef std::string str;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vi> MATRIX;

//const. list--->>>
const int MOD7 = int(1e9) + 7;
const int MOD9 = int(1e9) + 9;
const db Pi = 3.1415926535897932384626433832795;
const db eps = 0.000000001;
const ll Inf = 0x7FFFFFFFFFFFFFFF;

/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction

//Fast-I/O--->>>
inline str sin() {str s=""; while (1) {char c = gc(); if(c==' '|| c=='\n') break; s += c; } rtn s;}
inline ll in() {int n=0; ll x=0; char c = gc(); if(c == '-') n=1; while (c < '0' || c > '9') {c=gc(); if (c == '-') n = 1; }
	while (c >= '0' && c <= '9') {x = (x << 3) + (x << 1) + c - '0'; c = gc();} if (n) x = -x; rtn x;}
inline void put (ll a) {int n = (a < 0 ? 1 : 0); if (n) a = -a; char b[20]; int i = 0; do {b[i++] = a % 10 + '0'; a /= 10;}
	while (a); if (n) pc('-'); i--; while (i >= 0) pc(b[i--]); pc(' ');}
inline void putln(ll a) {int n = (a < 0 ? 1 : 0); if(n) a = -a; char b[20]; int i = 0; do{b[i++] = a % 10 + '0'; a /= 10;}
	while (a); if (n) pc('-'); i--; while (i >= 0) pc(b[i--]); pc('\n');}

//Other Utilities--->>>
inline ll fmm (ll a, ll b, ll m = MOD7) {ll r = 0; a %= m; b %= m; while (b > 0) {if (b & 1) {r += a; r %= m;} a += a; a %= m; b >>= 1;}rtn r % m;}
inline ll fme (ll a, ll b, ll m = MOD7) {ll r = 1; a %= m; while (b > 0) {if (b & 1){r *= a; r %= m;} a *= a; a %= m; b >>= 1;} rtn r % m;}
inline ll sfme (ll a, ll b, ll m = MOD7) {ll r = 1; a %= m; while (b > 0) {if (b & 1) r = fmm(r, a, m); a = fmm(a, a, m); b >>= 1;} rtn r % m;}
// For primefactorization after sieve
/*
bool v[nu]; int sp[nu];
void Sieve() {for (ll i = 2; i < nu; i += 2) sp[i] = 2; for (ll i = 3; i < nu; i += 2){if (!v[i]){sp[i] = i;
	for (ll j = i; (j*i) < nu; j += 2){if (!v[j*i])	v[j*i] = true, sp[j*i] = i;}}}}
vi fctz(ll k) {vi ans; while(k>1) {ans.push_back(sp[k]); k /= sp[k];} rtn ans;}
/*ll fact[1000001], invfact[1000001];
inline void init (ll MOD = MOD7){ll i; fact[0] = 1; for (i = 1; i <= 1000000; i++) fact[i] = (fact[i - 1] * i) % MOD;
	invfact[1000000] = fme (fact[1000000], MOD - 2, MOD); for (i = 1000000 - 1; i >= 0; i--) invfact[i] = (invfact[i + 1] * (i + 1)) % MOD;}
inline ll nCk (ll n, ll k, ll MOD = MOD7){rtn (((fact[n] * invfact[k]) % MOD) * invfact[n - k]) % MOD;}
inline ll nPk (ll n, ll k, ll MOD = MOD7){rtn ((fact[n] * invfact[k]) % MOD);}*/
//nCk in O(k)
ll NCK (ll n, ll k, ll MOD = MOD7) {ll res = 1; if (k > n - k) k = n - k; rep (i, k) {res *= (n - i); res /= (i+1);} rtn res % MOD;}
template <class T> T gcd (T a, T b) {if (b == 0) rtn a; rtn gcd (b, a % b);}
inline void eGCD(ll a, ll b, ll &x, ll &y) {if (b == 0) {x = 1, y = 0; rtn;} ll x1, y1; eGCD (b, a % b, x1, y1); x = y1; y = x1 - (a / b) * y1;}
template <class T> T lcm(T a, T b){rtn (a * b) / gcd(a, b);}
inline MATRIX mul (MATRIX &A, MATRIX &B, ll m = MOD7) {ll n = A.size(), i , j, k; MATRIX C(n, vector<ll>(n));
	for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % m; rtn C;}
inline MATRIX Mpow (MATRIX &A, ll x, ll m = MOD7) {ll n = A.size(), i; MATRIX B(n, vi(n)); for (i = 0; i < n; i++) B[i][i] = 1;
	while (x > 0) {if (x % 2) B = mul (B, A, m); x /= 2; A = mul (A, A, m);} rtn B;}
inline bool isSub (str &txt, str &s) {int pos = -1; bool ok = true; for (int i = 0; ok && i!=s.size(); i++) {ok = (pos = txt.find(s[i], pos+1)) != string::npos;} rtn ok;}
inline int countOne (ll n) {int count = 0; while (n) {n = n & (n-1); count++;} rtn count;}
inline str srev (str &s){str demo = ""; for (int i = s.length() - 1; i >= 0; i--) demo += s[i]; rtn demo;}
inline str tb (ll i) {str ans = ""; str arr = "01"; while (i) {ans += arr[i%2]; i = i / 2;} rtn srev(ans);}
inline ll maxSub (ll a[],ll n) {ll e = -Inf, s = 0; rep (i, n) {s += a[i]; if (e < s) e = s; if (s < 0) s = 0;} rtn e;}
inline ll minSub (ll a[],ll n) {ll e = Inf, s = 0; rep (i, n) {s += a[i]; if (e > s) e = s; if(s > 0) s = 0;} rtn e;}
template<class T> inline T Pow(T a, ll b){T c(1); while (b) {if (b & 1) c *= a; a *= a, b >>= 1;} rtn c;}
inline ll pp(int x) {ll r = 1; rep (i, x) r = r * 2LL; rtn r;}
//seive of Eratosthenes(prime's marked with 0)
/*ll isPrime[1000100];
void pinit() {isPrime[0] = 1, isPrime[1] = 1; for (ll i = 2; i * i <= 1000100; i++) {if (!isPrime[i]) {for (ll j = i*i; j < 1000100; j += i) isPrime[j] = 1;}}}*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const ll nu = 100100;

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	ll n = 0, m = 0, k = 0, lo = 0, hi = 0, mi = Inf, mx = -Inf, sum = 0, ans = 0, cnt=0, t = 0, v1 = 0, v2 = 0, x1 = 0, x2 = 0, x3 = 0, y1 = 0, y2 = 0, y3 = 0, curr = 0,
	q = 0, x = 0, y = 0, p = 0;
	str s, s1, s2;
	char c, c1, c2, *ptr;
	bool ok, okay;
	db dub=0;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//start here
	cin >> t;
	while(t--) {
		cin >> n;
		cout << max(0, n-1) << endl;
	}

}


/*  Praney Rai
  IIT(ISM) Dhanbad */

// Welcome ;)

#include <stdio.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define loop(i,a,b) for(ll i=(a); i<(b); i++)
#define rep(i, b) for(ll i=(0); i<(b); i++)
#define rep1(i, b) for (ll i=1; i<b; i++)
#define rrep(i, n) for(ll i=(n-1); i>=0; i--)
#define rloop(i,a,b) for(ll i=(b-1);i>=a;i--)
#define loopi(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define apac freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fill(a,v)	memset(a, v, sizeof(a))
#define si(n)	scanf("%lld",&n)
#define sc(n)   scanf("%c",&n)
#define sd(n)   scanf("%lf",&n)
#define pln(x) 	printf("%lld\n", x)
#define pr(x) 	printf("%lld ", x)
#define nl	printf("\n")
#define all(x) x.begin(), x.end()
#define remax(a,b) (a)=max((a),(b));
#define remin(a,b) (a)=min((a),(b));
#define xx first
#define yy second
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define rtn return
#define exit exit(0)
#define sz(x) ((ll)(x).size())
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define Mid(s,e) (s+(e-s)/2)
#define Abs(a, b)	Max(a-b,b-a)
#define kuch cout << "kuch bhi\n"
#define debug(x) cout << #x << ": " << x << "\n"
#define fout(a, b) cout << fixed << setprecision((b)) << (a)
#ifdef _WIN32
	#define pc putchar
	#define gc getchar
#else
	#define pc putchar_unlocked
	#define gc getchar_unlocked
#endif

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef std::string str;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vi> MATRIX;

//const. list--->>>
const int MOD7 = int(1e9) + 7;
const int MOD9 = int(1e9) + 9;
const db Pi = 3.1415926535897932384626433832795;
const db eps = 0.000000001;
const ll Inf = 0x7FFFFFFFFFFFFFFF;

/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction

//Fast-I/O--->>>
inline str sin() {str s=""; while (1) {char c = gc(); if(c==' '|| c=='\n') break; s += c; } rtn s;}
inline ll in() {int n=0; ll x=0; char c = gc(); if(c == '-') n=1; while (c < '0' || c > '9') {c=gc(); if (c == '-') n = 1; }
	while (c >= '0' && c <= '9') {x = (x << 3) + (x << 1) + c - '0'; c = gc();} if (n) x = -x; rtn x;}
inline void put (ll a) {int n = (a < 0 ? 1 : 0); if (n) a = -a; char b[20]; int i = 0; do {b[i++] = a % 10 + '0'; a /= 10;}
	while (a); if (n) pc('-'); i--; while (i >= 0) pc(b[i--]); pc(' ');}
inline void putln(ll a) {int n = (a < 0 ? 1 : 0); if(n) a = -a; char b[20]; int i = 0; do{b[i++] = a % 10 + '0'; a /= 10;}
	while (a); if (n) pc('-'); i--; while (i >= 0) pc(b[i--]); pc('\n');}

//Other Utilities--->>>
inline ll fmm (ll a, ll b, ll m = MOD7) {ll r = 0; a %= m; b %= m; while (b > 0) {if (b & 1) {r += a; r %= m;} a += a; a %= m; b >>= 1;}rtn r % m;}
inline ll fme (ll a, ll b, ll m = MOD7) {ll r = 1; a %= m; while (b > 0) {if (b & 1){r *= a; r %= m;} a *= a; a %= m; b >>= 1;} rtn r % m;}
inline ll sfme (ll a, ll b, ll m = MOD7) {ll r = 1; a %= m; while (b > 0) {if (b & 1) r = fmm(r, a, m); a = fmm(a, a, m); b >>= 1;} rtn r % m;}
// For primefactorization after sieve
/*
bool v[nu]; int sp[nu];
void Sieve() {for (ll i = 2; i < nu; i += 2) sp[i] = 2; for (ll i = 3; i < nu; i += 2){if (!v[i]){sp[i] = i;
	for (ll j = i; (j*i) < nu; j += 2){if (!v[j*i])	v[j*i] = true, sp[j*i] = i;}}}}
vi fctz(ll k) {vi ans; while(k>1) {ans.push_back(sp[k]); k /= sp[k];} rtn ans;}
/*ll fact[1000001], invfact[1000001];
inline void init (ll MOD = MOD7){ll i; fact[0] = 1; for (i = 1; i <= 1000000; i++) fact[i] = (fact[i - 1] * i) % MOD;
	invfact[1000000] = fme (fact[1000000], MOD - 2, MOD); for (i = 1000000 - 1; i >= 0; i--) invfact[i] = (invfact[i + 1] * (i + 1)) % MOD;}
inline ll nCk (ll n, ll k, ll MOD = MOD7){rtn (((fact[n] * invfact[k]) % MOD) * invfact[n - k]) % MOD;}
inline ll nPk (ll n, ll k, ll MOD = MOD7){rtn ((fact[n] * invfact[k]) % MOD);}*/
//nCk in O(k)
ll NCK (ll n, ll k, ll MOD = MOD7) {ll res = 1; if (k > n - k) k = n - k; rep (i, k) {res *= (n - i); res /= (i+1);} rtn res % MOD;}
template <class T> T gcd (T a, T b) {if (b == 0) rtn a; rtn gcd (b, a % b);}
inline void eGCD(ll a, ll b, ll &x, ll &y) {if (b == 0) {x = 1, y = 0; rtn;} ll x1, y1; eGCD (b, a % b, x1, y1); x = y1; y = x1 - (a / b) * y1;}
template <class T> T lcm(T a, T b){rtn (a * b) / gcd(a, b);}
inline MATRIX mul (MATRIX &A, MATRIX &B, ll m = MOD7) {ll n = A.size(), i , j, k; MATRIX C(n, vector<ll>(n));
	for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % m; rtn C;}
inline MATRIX Mpow (MATRIX &A, ll x, ll m = MOD7) {ll n = A.size(), i; MATRIX B(n, vi(n)); for (i = 0; i < n; i++) B[i][i] = 1;
	while (x > 0) {if (x % 2) B = mul (B, A, m); x /= 2; A = mul (A, A, m);} rtn B;}
inline bool isSub (str &txt, str &s) {int pos = -1; bool ok = true; for (int i = 0; ok && i!=s.size(); i++) {ok = (pos = txt.find(s[i], pos+1)) != string::npos;} rtn ok;}
inline int countOne (ll n) {int count = 0; while (n) {n = n & (n-1); count++;} rtn count;}
inline str srev (str &s){str demo = ""; for (int i = s.length() - 1; i >= 0; i--) demo += s[i]; rtn demo;}
inline str tb (ll i) {str ans = ""; str arr = "01"; while (i) {ans += arr[i%2]; i = i / 2;} rtn srev(ans);}
inline ll maxSub (ll a[],ll n) {ll e = -Inf, s = 0; rep (i, n) {s += a[i]; if (e < s) e = s; if (s < 0) s = 0;} rtn e;}
inline ll minSub (ll a[],ll n) {ll e = Inf, s = 0; rep (i, n) {s += a[i]; if (e > s) e = s; if(s > 0) s = 0;} rtn e;}
template<class T> inline T Pow(T a, ll b){T c(1); while (b) {if (b & 1) c *= a; a *= a, b >>= 1;} rtn c;}
inline ll pp(int x) {ll r = 1; rep (i, x) r = r * 2LL; rtn r;}
//seive of Eratosthenes(prime's marked with 0)
/*ll isPrime[1000100];
void pinit() {isPrime[0] = 1, isPrime[1] = 1; for (ll i = 2; i * i <= 1000100; i++) {if (!isPrime[i]) {for (ll j = i*i; j < 1000100; j += i) isPrime[j] = 1;}}}*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const ll nu = 100100;

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	ll n = 0, m = 0, k = 0, lo = 0, hi = 0, mi = Inf, mx = -Inf, sum = 0, ans = 0, cnt=0, t = 0, v1 = 0, v2 = 0, x1 = 0, x2 = 0, x3 = 0, y1 = 0, y2 = 0, y3 = 0, curr = 0,
	q = 0, x = 0, y = 0, p = 0;
	str s, s1, s2;
	char c, c1, c2, *ptr;
	bool ok, okay;
	db dub=0;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//start here
	cin >> t;
	while(t--) {
		cin >> n;
		cout << n-2 << endl;
	}

}


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

int main()
{int t,n;
cin>>t;
int *arr=new int[t];
for(int i=0 ;i< t; i++)
   {cin>>n;
if(n>1)
  cout<<n-2<<endl;
else
    cout<<0<<endl;

   }
return 0;
}


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

int main()
{int t,n;
cin>>t;
int *arr=new int[t];
for(int i=0 ;i< t; i++)
   {cin>>n;
if(n>1)
  cout<<n-2,0;
else
    cout<<0,0;

   }

}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define EPS 1e-9
#define MOD 1000000007

/*
*
*Zaiiiin
*
*/

using namespace std;

typedef pair<int,int> ii;
const double pi = acos(-1);
const int n_ = 1e5 + 5;

int t, n;

int main()
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
  #else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
  #endif

  scanf("%d", &t);
  while(t--){
    scanf("%d", &n);
    printf("%d\n", n-2);
  }
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define EPS 1e-9
#define MOD 1000000007

/*
*
*Zaiiiin
*
*/

using namespace std;

typedef pair<int,int> ii;
const double pi = acos(-1);
const int n_ = 1e5 + 5;

int t, n;

int main()
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
  #else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
  #endif

  scanf("%d", &t);
  while(t--){
    scanf("%d", &n);
    printf("%d\n", max(n-2, 0));
  }
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define EPS 1e-9
#define MOD 1000000007

/*
*
*Zaiiiin
*
*/

using namespace std;

typedef pair<int,int> ii;
const double pi = acos(-1);
const int n_ = 1e5 + 5;

int t, n;

int main()
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
  #else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
  #endif

  scanf("%d", &t);
  while(t--){
    scanf("%d", &n);
    printf("%d\n", n/3);
  }
  return 0;
}


#include "bits/stdc++.h"

using namespace std;

#define ll long long int
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define NFOR(i,a,b) for(ll i=a;i>b;i--)
#define sz(a) int((a).size())
#define all(c) c.begin(),c.end()
#define find(c, x) (c.find(x)!=c.end())
#define tr(c,i) for(typeof((c).begin() i=(c).begin();i!=(c).end();i++)
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 200005

int main(){
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        else cout<<max((ll)0,n-2)<<endl;
    }
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

#define ll long long int
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define NFOR(i,a,b) for(ll i=a;i>b;i--)
#define sz(a) int((a).size())
#define all(c) c.begin(),c.end()
#define find(c, x) (c.find(x)!=c.end())
#define tr(c,i) for(typeof((c).begin() i=(c).begin();i!=(c).end();i++)
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 200005

int main(){
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        cout<<max((ll)0,n-2)<<endl;
    }
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

#define ll long long int
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define NFOR(i,a,b) for(ll i=a;i>b;i--)
#define sz(a) int((a).size())
#define all(c) c.begin(),c.end()
#define find(c, x) (c.find(x)!=c.end())
#define tr(c,i) for(typeof((c).begin() i=(c).begin();i!=(c).end();i++)
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 200005

int main(){
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        if(n==2) cout<<0<<endl;
        else cout<<max((ll)1,n-2)<<endl;
    }
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

#define ll long long int
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define NFOR(i,a,b) for(ll i=a;i>b;i--)
#define sz(a) int((a).size())
#define all(c) c.begin(),c.end()
#define find(c, x) (c.find(x)!=c.end())
#define tr(c,i) for(typeof((c).begin() i=(c).begin();i!=(c).end();i++)
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 200005

int main(){
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        if(n==2) cout<<0;
        else cout<<max((ll)1,n-2)<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int num;
    while(n--){
        scanf("%d",&num);
        printf("%d",num>2?num-2:0);
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int num;
    while(n--){
        scanf("%d",&num);
        printf("%d\n",num>2?num-2:0);
    }
}


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

////////////// Prewritten code follows. Look down for solution. ////////////////
#define x first
#define y second
#define len(x) ((int)(x).size())
using pii = pair<int, int>;
using ll = long long;
using llu = long long unsigned;
using ld = long double;

const ld EPS = 1e-9;
inline int cmp(ld x, ld y = 0, ld tol = EPS) {
  return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

const int MOD = 1;
inline int mod (ll x, int m = MOD) {
  return (int)(((x%m) + m)%m);
}

////////////////////////// Solution starts below. //////////////////////////////

int t, n;

int main () {
	scanf ("%d", &t);
	while (t--) {
		scanf ("%d", &n);
		if (n == 1)
			printf ("%d\n", 0);
		else
			printf ("%d\n", n-2);
	}

	return 0;
}


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

////////////// Prewritten code follows. Look down for solution. ////////////////
#define x first
#define y second
#define len(x) ((int)(x).size())
using pii = pair<int, int>;
using ll = long long;
using llu = long long unsigned;
using ld = long double;

const ld EPS = 1e-9;
inline int cmp(ld x, ld y = 0, ld tol = EPS) {
  return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

const int MOD = 1;
inline int mod (ll x, int m = MOD) {
  return (int)(((x%m) + m)%m);
}

////////////////////////// Solution starts below. //////////////////////////////

int t, n;

int main () {
	scanf ("%d", &t);
	while (t--) {
		scanf ("%d", &n);
		printf ("%d\n", n/2);
	}

	return 0;
}


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

////////////// Prewritten code follows. Look down for solution. ////////////////
#define x first
#define y second
#define len(x) ((int)(x).size())
using pii = pair<int, int>;
using ll = long long;
using llu = long long unsigned;
using ld = long double;

const ld EPS = 1e-9;
inline int cmp(ld x, ld y = 0, ld tol = EPS) {
  return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

const int MOD = 1;
inline int mod (ll x, int m = MOD) {
  return (int)(((x%m) + m)%m);
}

////////////////////////// Solution starts below. //////////////////////////////

int t, n;

int main () {
	scanf ("%d", &t);
	while (t--) {
		scanf ("%d", &n);
		printf ("%d\n", n-2);
	}

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,t,i;
    cin>>t;

    for(i=1;i<=t;i++)
    {
        cin>>n;
        if(n==1)
            cout<<"0";
            else
            cout<<n-2;

    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,t,i;
    cin>>t;

    for(i=1;i<=t;i++)
    {
        cin>>n;
        if(n==1)
            cout<<"0"<<endl;
            else
            cout<<n-2<<endl;

    }
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<deque>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
#define lli long long int
#define ull unsigned long long int
#define ff first
#define MOD 1000000007
#define ss second
#define print(containeer) \
for(auto iterator:containeer)cout<<iterator<<" ";cout<<endl;
#define PI 3.14159265
#define N 1000010
void solve()
{

    lli a,b,c,d,i,j,k,l;
   cin>>a;
   cout<<a-2<<endl;

}
int main()
{

    lli a=1;
   cin>>a;
    while(a--)
        solve();
}


#include<iostream>
#include<stdio.h>
#include<deque>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
#define lli long long int
#define ull unsigned long long int
#define ff first
#define MOD 1000000007
#define ss second
#define print(containeer) \
for(auto iterator:containeer)cout<<iterator<<" ";cout<<endl;
#define PI 3.14159265
#define N 1000010
void solve()
{

    lli a,b,c,d,i,j,k,l;
   cin>>a;
   cout<<max((lli)0,a-2)<<endl;

}
int main()
{

    lli a=1;
   cin>>a;
    while(a--)
        solve();
}


#include <iostream>

using namespace std;

int t;

int main()
{
    cin>>t;

    int n;

    for(int i = 1; i <= t; i++)
    {
        cin>>n;

        if(n >= 2)
            cout<<n - 2;
        else{
            cout<<n;
        }

    }

}


#include <iostream>

using namespace std;

int t;

int main()
{
    cin>>t;

    int n;

    for(int i = 1; i <= t; i++)
    {
        cin>>n;

        if(n >= 2)
            cout<<n - 2<<endl;
        else{
            cout<<0<<endl;
        }

    }

}


#include <iostream>

using namespace std;

int main()
{
    cout<<1<<endl;
}


#include <iostream>

using namespace std;

int t;

int main()
{
    cin>>t;

    int n;

    for(int i = 1; i <= t; i++)
    {
        cin>>n;

        if(n > 2)
            cout<<n - 2;
        else{
            cout<<n;
        }

    }

}


#include <iostream>

using namespace std;

int t;

int main()
{
    ios::sync_with_stdio( false );
    cin.tie();

    cin>>t;

    int n;

    for(int i = 1; i <= t; i++)
    {
        cin>>n;

        if(n >= 2)
            cout<<n - 2<<endl;
        else{
            cout<<0<<endl;
        }

    }

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        cin >> n;
        cout << n - 2 << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        cin >> n;
        if (n < 2) {n = 0;}
        if (n > 1) {n = n - 2;}
        cout << n << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        cin >> n;
        if (n > 1) {n = n - 2;}
        if (n < 2) {n = 0;}
        cout << n << endl;
    }
}


    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1e3 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;
    const long long OO = 1e18+25;
    #define par pair<pair<int,int>, int>
    #define f first
    #define s second

    int t, n;
    int main()
    {
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n)
            printf("%d\n",(n+2)/3);
        }
        return 0;
    }


    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1e3 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;
    const long long OO = 1e18+25;
    #define par pair<pair<int,int>, int>
    #define f first
    #define s second

    int t, n;
    int main()
    {
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            printf("%d\n",n-(n<3?0:2));
        }
        return 0;
    }


    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1e3 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;
    const long long OO = 1e18+25;
    #define par pair<pair<int,int>, int>
    #define f first
    #define s second

    int t, n;
    int main()
    {
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            printf("%d\n",n-(n<2?n:2));
        }
        return 0;
    }


    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1e3 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;
    const long long OO = 1e18+25;
    #define par pair<pair<int,int>, int>
    #define f first
    #define s second

    int t, n;
    int main()
    {
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            printf("%d\n",(n+2)/3);
        }
        return 0;
    }


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;

    for ( int i = 0 ; i < n ; ++i )
    {
        int x;
        cin >> x;
        if ( x == 1 )
            cout << 0 << endl;
        else
            cout << x - 2 << endl;
    }

}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin << n;

    for ( int i = 0 ; i < n ; ++i )
    {
        int x;
        f >> x;
        if ( x == 1 )
            cout << 0;
        else
            cout << x - 2 << endl;
    }

}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;

    for ( int i = 0 ; i < n ; ++i )
    {
        int x;
        cin >> x;
        if ( x == 1 )
            cout << 0;
        else
            cout << x - 2 << endl;
    }

}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(fals)
    cin << n;

    for ( int i = 0 ; i < n ; ++i )
        int x,
        f >> x,
        if ( x == 1 )
            cout << 0;
        else
            cout << x - 2 << endl;

}


#include<iostream>
#include<string.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int len=s.length();

    int max_length=0;
    for(int i=0;i<len;i++)
    {
        for(int j=i+1;j<=len;j++)
        {
            int lent=j-i;
            string s1=s.substr(i,lent);
            for(int k=i+1;k<=(len-lent);k++)
                if((s.substr(k,lent)==s1)&&(len!=lent))
                {
                    max_length=max(max_length,lent);
                    break;
                }

        }
    }
    cout<<max_length;

}


#include<iostream>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(int i=0;i<t-1;i++)
    {
        int n;
        cin>>n;
        cout<<max(0,n-2)<<endl;
    }
    int n;
    cin>>n;
    cout<<max(0,n-2);
}


#include <iostream>
#include <string>
#include <streambuf>
#include <fstream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <map>
#include <set>
#include <stdlib.h>
#include <cstdio>
#include <vector>
#include <queue>
#include <math.h>
#include <climits>
#include <bitset>

#define mp make_pair
#define pb push_back
#define ll long long
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define sc4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define pf1(a) printf("%lld\n",a)
#define pf2(a,b) printf("%lld %lld\n",a,b)
#define pf3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pf4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define pfy printf("YES\n")
#define pfn printf("NO\n")
#define pfm1 printf("-1\n")
//#define pf1 printf("1\n")
#define pfnl printf("\n")
#define pfsp printf(" ")

#define memm1(arr) memset(arr,-1,sizeof(arr))
#define mem0(arr) memset(arr,0,sizeof(arr))
#define mem1(arr) memset(arr,1,sizeof(arr))

using namespace std;
bool wayToSort(char i, char j) { return i>j; }

int main()
{
    ll n,t;
    sc1(t);
    for(ll i=0;i<t;i++)
    {
        sc1(n);
        ll a=0;
        pf1(max(a,n-2));
    }

    return 0;
}


#include <iostream>
#include <string>
#include <streambuf>
#include <fstream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <map>
#include <set>
#include <stdlib.h>
#include <cstdio>
#include <vector>
#include <queue>
#include <math.h>
#include <climits>
#include <bitset>

#define mp make_pair
#define pb push_back
#define ll long long
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define sc4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define pf1(a) printf("%lld\n",a)
#define pf2(a,b) printf("%lld %lld\n",a,b)
#define pf3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pf4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define pfy printf("YES\n")
#define pfn printf("NO\n")
#define pfm1 printf("-1\n")
#define pf1 printf("1\n")
#define pfnl printf("\n")
#define pfsp printf(" ")

#define memm1(arr) memset(arr,-1,sizeof(arr))
#define mem0(arr) memset(arr,0,sizeof(arr))
#define mem1(arr) memset(arr,1,sizeof(arr))

using namespace std;
bool wayToSort(char i, char j) { return i>j; }

map < ll, ll > sock;

int main()
{
    ll n;
    sc1(n);
    ll count=0,maxx=0;
    for(ll i=0;i<n;i++)
    {
        ll a;
        sc1(a);
        pf1;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t;
    cin>>t;
    // make everyone as friend so there are n-1 total friends , break edge 1 and n , so now 1 and n has n-2 friends and all other have n-1 . when 1 and n leave n-2 people are left with n-2-1 friends at max , so they will stay
    while(t--){
        ll n;
        cin>>n;
        if(n>=3)
        {cout<<n-2<<endl;}
        else{
            cout<<0<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        cout<<n-2<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        if(n>=3)
        {cout<<n-2<<endl;}
        else{
            cout<<0<<endl;
        }
    }
}


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

int main()
{
	int t;
	cin>t;
	while(t--)
	{
		int n;
		cin>>n;
		cout<<n-2<<endl;
	}

	return 0;
}


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

int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		int n;
		cin>>n;
		if(n==1)cout<<0<<endl;
		else
		cout<<n-2<<endl;
	}

	return 0;
}


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

int main()
{
	int t;
	cin>>t;

	while(t--)
	{
		int n;
		cin>>n;
		if(n==1)cout<<0<<endl;
		else if(n==2)cout<<2<<endl;
		else
		cout<<n-2<<endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n==1)
        cout<<0<<'\n';
        else
        cout<<1<<'\n';
    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n==1)
        cout<<0<<'\n';
        else
        cout<<n-2<<'\n';
    }

}


#include <iostream>
using namespace std;

int main() {
	int n,a;
	cin >> n;
	if(n==1){
		a=0;
	}
	else{
		a=n-2;
	}
	cout << a;
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t,n,a;
	cin >> t;
	for(int i=0;i<t;i++){
		cin >> n;
		if(n==1){
			a=0;
		}
		else{
			a=n-2;
		}
		cout << a << endl;
	}

	return 0;
}


#include <iostream>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  int t, n;
  cin >> t;
  while(t--){
    cin >> n;
    cout << ((n < 3) ? n : n-2) << endl;
  }
}


#include <iostream>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  int t, n;
  cin >> t;
  while(t--){
    cin >> n;
    cout << max(0, n-2) << endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int t,n;
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>t;
    while(t--)
    {
        cin>>n;
        n>2 ? cout<<n-2<<endl : cout<<0<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int t,n;
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>t;
    while(t--)
    {
        cin>>n;
        cout<<n-2<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main(){

	//auther aniket bansal //

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
		int n;
		cin>>n;
		cout<<n-2<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

	//auther aniket bansal //

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
		int n;
		cin>>n;
		if(n <=2){
			cout<<0<<endl;
		}
		else{
			cout<<n-2<<endl;
		}

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int a,b,c,d;
    cin >> a;
    while ( a > 0)
        {
            cin >> b;
            cout << max(0, b - 2) << "\n";
            a --;
        }

}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int a,b,c,d;
    cin >> a;
    while ( a > 0)
        {
            cin >> b;
            cout << max(0, b - 2) << "\n";
            a --;
        }

}    q


#include<bits/stdc++.h>

using namespace std;

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

	int t;
	cin>>t;

	while(t--)
	{
		int n;
		cin>>n;
		cout<<n-2<<'\n';
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

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

	int t;
	cin>>t;

	while(t--)
	{
		int n;
		cin>>n;
		int ref = 0;

		cout<<max(n-2,ref)<<'\n';
	}
	return 0;
}


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

int main() {
	ll t;   cin>>t;
	while(t--)
	{
	    ll n;
	    cin>>n;
	    cout<<n-2<<endl;
	}
	return 0;
}


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

int main() {
	ll t;   cin>>t;
	while(t--)
	{
	    ll n;
	    cin>>n;
	    if(n%2==0)
	    cout<<(n+1)/2<<endl;
	    else
	    cout<<(n+1)/2-1<<endl;
	}
	return 0;
}


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

int main() {
	ll t;   cin>>t;
	while(t--)
	{
	    ll n;
	    cin>>n;
	    if(n==1)
	    cout<<0<<endl;
	    else if (n==2)
	    cout<<0<<endl;
	    else
	    cout<<n-2<<endl;
	}
	return 0;
}


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

int main() {
	ll t;   cin>>t;
	while(t--)
	{
	    ll n;
	    cin>>n;
	    if(n==1)
	    cout<<0<<endl;
	    else if (n==2)
	    cout<<1<<endl;
	    else
	    cout<<n-2<<endl;
	}
	return 0;
}


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

int main() {
	ll t;   cin>>t;
	while(t--)
	{
	    ll n;
	    cin>>n;
	    if(n==1)
	    cout<<0<<endl;
	    else if n==2)
	    cout<<1<<endl;
	    else
	    cout<<n-2<<endl;
	}
	return 0;
}


//Problema interesante debido a  lo complejo que parecia, cuando tenia una solucion obvia
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        }
   for(int i=0;i<n;i++){
       if(arr[i]!=1){
        cout<<arr[i]-2<<endl;
        }else cout<<0<<endl;}
  return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
using namespace std;
int num[70],fre[100],ans=0;
bool yes,y;
int main()
{
    for(int i=0;i<6;i++)
    {
        cin>>num[i];
        fre[num[i]]++;
    }
    yes=0;ans=0;
    for(int i=0;i<=10;i++)
    {
        if(fre[i]>=4){fre[i]-=4;yes=1;}
    }
    if(yes){
        ans=2;
        for(int i=0;i<=10;i++)
        {
            if(fre[i]==2)ans=1;
        }
    }
    if(ans==0)cout<<"Alien"<<endl;
    else if(ans==1)cout<<"Elephant"<<endl;
    else if(ans==2)cout<<"Bear"<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<stdio.h>
using namespace std;
int m,n,num[(2*100000)+5],b=-1,t;
string str,btr;
char u[11];
int main()
{
    int l=0;
    cin>>n>>m;
    if(m==1){cout<<n<<endl;return 0;}
    if(n==1){cout<<'0'<<endl;return 0;}
    for(int i=0;i<n;i++){cin>>num[i];}
    if(m!=1){
        for(int i=1;i<n;i++){sprintf(u,"%d",num[i]-num[i-1]);str+=u;}
        for(int i=0;i<m;i++)cin>>num[i];
        for(int i=1;i<m;i++){sprintf(u,"%d",num[i]-num[i-1]);btr+=u;}
        while((b=str.find(btr,b+1))!=-1)
        {
            l++;
        }
    }else {
        cin>>t;
        for(int i=0;i<n;i++)if(num[i]==t)l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<stdio.h>
using namespace std;
int m,n,num[(2*100000)+5],b=-1,t;
string str,btr;
char u[11];
int main()
{
    int l=0;
    cin>>n>>m;
    for(int i=0;i<n;i++){cin>>num[i];}
    if(m!=1){
        for(int i=1;i<n;i++){sprintf(u,"%d",num[i]-num[i-1]);str+=u;}
        for(int i=0;i<m;i++)cin>>num[i];
        for(int i=1;i<m;i++){sprintf(u,"%d",num[i]-num[i-1]);btr+=u;}
        while((b=str.find(btr,b+1))!=-1)
        {
            l++;
        }
    }else {
        cin>>t;
        for(int i=0;i<n;i++)if(num[i]==t)l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<stdio.h>
using namespace std;
int m,n,num[(2*100000)+5],b=-1,t;
string str,btr;
char u[11];
int main()
{
    int l=0;
    cin>>n>>m;
    if(m==1){cout<<n<<endl;return 0;}
    if(n==1){cout<<'0'<<endl;return 0;}
    for(int i=0;i<n;i++){cin>>num[i];if(i>1)sprintf(u,"%d*",num[i]-num[i-1]);str+=u;}
    for(int i=0;i<m;i++){cin>>num[i];if(i>1)sprintf(u,"%d*",num[i]-num[i-1]);btr+=u;}
    while((b=str.find(btr,b+1))!=-1)
    {
        l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int m,n,num[(2*100000)+5],teq[(2*100000)+5],dp[(2*100000)+5];
vector<int>vec;
vector<int>::iterator it;
int main()
{

    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>num[i];
    vec.push_back(-1);
    for(int i=1;i<n;i++)vec.push_back(num[i]-num[i-1]);
    for(int i=0;i<m;i++)cin>>num[i];
    for(int i=1;i<m;i++)
    {
        it=vec.begin();
        while((it=find(it+1,vec.end(),num[i]-num[i-1]))!=vec.end())
        {
            if(i!=1){
                if(it-vec.begin()!=0){
                    if(teq[it-vec.begin()-1]==i-1)
                        teq[it-vec.begin()]=i;
                }
            }else teq[it-vec.begin()]=i;
        }
    }
    int l=0;
    for(int i=0;i<n;i++)
    {
        if(teq[i]==m-1)l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<stdio.h>
using namespace std;
int m,n,num[(2*100000)+5],b=-1,t;
string str,btr;
char u[11];
int main()
{
    int l=0;
    cin>>n>>m;
    if(m==1){cout<<n<<endl;return 0;}
    if(n==1){cout<<'0'<<endl;return 0;}
    for(int i=0;i<n;i++){cin>>num[i];if(i>1){sprintf(u,"%d",(num[i]-num[i-1]*2)%10);str+=u;}}
    for(int i=0;i<m;i++){cin>>num[i];if(i>1){sprintf(u,"%d",(num[i]-num[i-1]*2)%10);btr+=u;}}
    while((b=str.find(btr,b+1))!=-1)
    {
        l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int m,n,num[(2*100000)+5],teq[(2*100000)+5],dp[(2*100000)+5];
vector<int>vec;
vector<int>::iterator it,bt;
int main()
{

    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>num[i];
    for(int i=1;i<n;i++)vec.push_back(num[i]-num[i-1]);
    for(int i=0;i<m;i++)cin>>num[i];
    for(int i=1;i<m;i++)
    {
        it=vec.begin();
        while((it=find(it==vec.begin()?it:it+1,vec.end(),num[i]-num[i-1]))!=vec.end())
        {
            if(i!=1){
                if(teq[it-vec.begin()-1]==i-1)
                    teq[it-vec.begin()]=i;
            }else teq[it-vec.begin()]=i;
        }
    }
    int l=0;
    for(int i=0;i<n;i++)
    {
        if(teq[i]==1){dp[i]=1;continue;}
        if(teq[i]-1==teq[i-1] && dp[i-1]){
            if(teq[i]==m-1)
            {
                l++;
            }
            dp[i]=1;
        }
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<stdio.h>
using namespace std;
int m,n,num[(2*100000)+5],b=-1,t;
string str,btr;
char u[11];
int main()
{
    int l=0;
    scanf("%d%d",&n,&m);
    if(m==1){cout<<n<<endl;return 0;}
    if(n==1){cout<<'0'<<endl;return 0;}
    for(int i=0;i<n;i++){
        scanf("%d",&num[i]);
        if(i>0){sprintf(u,"%d ",num[i]-num[i-1]);str+=u;}
    }
    for(int i=0;i<m;i++){scanf("%d",&num[i]);if(i>0){sprintf(u,"%d ",num[i]-num[i-1]);btr+=u;}}
    while((b=str.find(btr,b+1))!=-1)
    {
        l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<stdio.h>
using namespace std;
int m,n,num[(2*100000)+5],b=-1,t;
string str,btr;
char u[11];
int main()
{
    int l=0;
    cin>>n>>m;
    if(m==1){cout<<n<<endl;return 0;}
    if(n==1){cout<<'0'<<endl;return 0;}
    for(int i=0;i<n;i++){cin>>num[i];if(i>1){sprintf(u,"%d*",num[i]-num[i-1]);str+=u;}}
    for(int i=0;i<m;i++){cin>>num[i];if(i>1){sprintf(u,"%d*",num[i]-num[i-1]);btr+=u;}}
    while((b=str.find(btr,b+1))!=-1)
    {
        l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
long long m,n,num[(2*100000)+5],teq[(2*100000)+5];
vector<long long>vec;
vector<long long>::iterator it;
int main()
{

    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>num[i];
    vec.push_back(-1);
    for(int i=1;i<n;i++)vec.push_back(num[i]-num[i-1]);
    for(int i=0;i<m;i++)cin>>num[i];
    for(int i=1;i<m;i++)
    {
        it=vec.begin();
        while((it=find(it+1,vec.end(),num[i]-num[i-1]))!=vec.end())
        {
            if(i==1)teq[it-vec.begin()]=1;
            else{
                if(teq[it-vec.begin()-1]==i-1)
                    teq[it-vec.begin()]=i;
            }
        }
    }
    int l=0;
    for(int i=0;i<n;i++)
    {
        if(teq[i]==m-1)l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
long long m,n,num[(2*100000)+5],teq[(2*100000)+5];
vector<long long>vec;
vector<long long>::iterator it;
int main()
{

    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>num[i];
    vec.push_back(-1);
    for(int i=1;i<n;i++)vec.push_back(num[i]-num[i-1]);
    for(int i=0;i<m;i++)cin>>num[i];
    for(int i=1;i<m;i++)
    {
        it=vec.begin();
        while((it=find(it+1,vec.end(),num[i]-num[i-1]))!=vec.end())
        {
            if(i==1)teq[it-vec.begin()]=1;
            else{
                if(it-vec.begin()!=0){
                    if(teq[it-vec.begin()-1]==i-1)
                        teq[it-vec.begin()]=i;
                }
            }
        }
    }
    int l=0;
    for(int i=0;i<n;i++)
    {
        if(teq[i]==m-1)l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<stdio.h>
using namespace std;
int m,n,num[(2*100000)+5],b=-1,t;
string str,btr;
char u[11];
int main()
{
    int l=0;
    cin>>n>>m;
    if(m==1){cout<<n<<endl;return 0;}
    if(n==1){cout<<'0'<<endl;return 0;}
    for(int i=0;i<n;i++){cin>>num[i];}
    if(m!=1){
        for(int i=1;i<n;i++){sprintf(u,"%d*",num[i]-num[i-1]);str+=u;}
        for(int i=0;i<m;i++)cin>>num[i];
        for(int i=1;i<m;i++){sprintf(u,"%d*",num[i]-num[i-1]);btr+=u;}
        while((b=str.find(btr,b+1))!=-1)
        {
            l++;
        }
    }else {
        cin>>t;
        for(int i=0;i<n;i++)if(num[i]==t)l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int m,n,num[(2*100000)+5],teq[(2*100000)+5],dp[(2*100000)+5];
vector<int>vec;
vector<int>::iterator it;
int main()
{

    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>num[i];
    vec.push_back(-1);
    for(int i=1;i<n;i++)vec.push_back(num[i]-num[i-1]);
    for(int i=0;i<m;i++)cin>>num[i];
    for(int i=1;i<m;i++)
    {
        it=vec.begin();
        while((it=find(it+1,vec.end(),num[i]-num[i-1]))!=vec.end())
        {
            if(i!=1){
                if(it-vec.begin()!=0){
                    if(teq[it-vec.begin()-1]==i-1)
                        teq[it-vec.begin()]=i;
                }
            }else teq[it-vec.begin()]=i;
        }
    }
    int l=0;
    for(int i=0;i<n;i++)
    {
        if(teq[i]==1)l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<stdio.h>
using namespace std;
int m,n,num[(2*100000)+5],b=-1,t;
string str,btr;
char u[11];
int main()
{
    int l=0;
    scanf("%d%d",&n,&m);
    if(m==1){cout<<n<<endl;return 0;}
    if(n==1){cout<<'0'<<endl;return 0;}
    for(int i=0;i<n;i++){
        scanf("%d",&num[i]);
        if(i>0){sprintf(u,"%d",(num[i]-num[i-1]+1));str+=u;}
    }
    for(int i=0;i<m;i++){scanf("%d",&num[i]);if(i>0){sprintf(u,"%d",(num[i]-num[i-1]+1));btr+=u;}}
    while((b=str.find(btr,b+1))!=-1)
    {
        l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int m,n,num[(2*100000)+5],teq[(2*100000)+5],dp[(2*100000)+5];
vector<int>vec;
vector<int>::iterator it;
int main()
{

    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>num[i];
    vec.push_back(-1);
    for(int i=1;i<n;i++)vec.push_back(num[i]-num[i-1]);
    for(int i=0;i<m;i++)cin>>num[i];
    for(int i=1;i<m;i++)
    {
        it=vec.begin();
        while((it=find(it+1,vec.end(),num[i]-num[i-1]))!=vec.end())
        {
            if(i!=1){
                if(teq[it-vec.begin()-1]==i-1)
                    teq[it-vec.begin()]=i;
            }else teq[it-vec.begin()]=i;
        }
    }
    int l=0;
    for(int i=0;i<n;i++)
    {
        if(teq[i]==1){dp[i]=1;continue;}
        if(teq[i]-1==teq[i-1] && dp[i-1]){
            if(teq[i]==m-1)
            {
                l++;
            }
            dp[i]=1;
        }
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int m,n,num[(2*100000)+5],teq[(2*100000)+5];
vector<int>vec;
vector<int>::iterator it;
int main()
{

    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>num[i];
    vec.push_back(-1);
    for(int i=1;i<n;i++)vec.push_back(num[i]-num[i-1]);
    for(int i=0;i<m;i++)cin>>num[i];
    for(int i=1;i<m;i++)
    {
        it=vec.begin();
        while((it=find(it+1,vec.end(),num[i]-num[i-1]))!=vec.end())
        {
            if(i!=1){
                if(it-vec.begin()!=0){
                    if(teq[it-vec.begin()-1]==i-1)
                        teq[it-vec.begin()]=i;
                }
            }else teq[it-vec.begin()]=1;
        }
    }
    int l=0;
    for(int i=0;i<n;i++)
    {
        if(teq[i]==m-1)l++;
    }
    cout<<l<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
long long m,n,num[(2*100000)+5],teq[(2*100000)+5];
vector<long long>vec;
vector<long long>::iterator it;
int main()
{

    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>num[i];
    vec.push_back(-1);
    for(int i=1;i<n;i++)vec.push_back(num[i]-num[i-1]);
    for(int i=0;i<m;i++)cin>>num[i];
    for(int i=1;i<m;i++)
    {
        it=vec.begin();
        while((it=find(it+1,vec.end(),num[i]-num[i-1]))!=vec.end())
        {
            if(i!=1){
                if(it-vec.begin()!=0){
                    if(teq[it-vec.begin()-1]==i-1)
                        teq[it-vec.begin()]=i;
                }
            }else teq[it-vec.begin()]=1;
        }
    }
    int l=0;
    for(int i=0;i<n;i++)
    {
        if(teq[i]==m-1)l++;
    }
    cout<<l<<endl;
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
#define MP make_pair
#define PB push_back
#define SZ(x) int((x).size())
#define SQR(x) (x)*(x)
#define SIGN(x) (x>1)-(x<0)
typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> pii; typedef pair<long,long> pll; typedef vector<int,int> vii;
const LD PI = 3.1415926535897932384626433832795L; const LD EPS = 1e-9;
LL gcd (LL a, LL b) {while(b){a %= b;swap (a, b);}return a;} LL lcm(const LL a,const LL b){return a/gcd(a,b)*b;}LL sign(const LL x){return (x>0)-(x<0);}
template<class T>const T sqr(const T x){return x*x;}
template<class T> const T binpow(const T a, const ULL n, const T modulo){return n == 0 ? 1 : sqr ( binpow ( a, n/2, modulo ) ) % modulo * ( n % 2 ? a : 1 ) % modulo;}

const int MAXN = int(2e5)+42;
const LL MIND = 1LL - (LL)1e9;
const ULL KEY = 2000000011;//int(1e9)+7;
int a[MAXN], b[MAXN];
int da[MAXN], db[MAXN];
ULL power_key[MAXN], prefix_hash_a[MAXN];

int main ( ) {
    ios::sync_with_stdio ( false );

	int n, w;
	cin >> n >> w;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = 0; i < w; i++){
		cin >> b[i];
	}
	for (int i = 0; i < n-1; i++){
		da[i] = a[i+1] - a[i];
	}
	for (int i = 0; i < w-1; i++){
		db[i] = b[i+1] - b[i];
	}
	power_key[0] = 1;
	for (int i = 1; i <= max(n,w); i++){
		power_key[i] = power_key[i-1] * KEY;
	}
	prefix_hash_a[0] = da[0] - MIND;
	for (int i = 1; i < n-1; i++){
		prefix_hash_a[i] = LL ( da[i] - MIND ) * power_key[i] + prefix_hash_a[i-1];
	}
	ULL hash_db = 0;
	for (int i = 0; i < w-1; i++){
		hash_db += LL ( db[i] - MIND ) * power_key[i];
	}
	int result = 0;
	for (int i = 0; i+w <= n; i++){
		LL hash = prefix_hash_a[i+w-2];
		if ( i ) hash -= prefix_hash_a[i-1];
		if ( hash == hash_db * power_key[i] ) {
			++result;
		}
	}
	cout << result << endl;

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
#define MP make_pair
#define PB push_back
#define SZ(x) int((x).size())
#define SQR(x) (x)*(x)
#define SIGN(x) (x>1)-(x<0)
typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> pii; typedef pair<long,long> pll; typedef vector<int,int> vii;
const LD PI = 3.1415926535897932384626433832795L; const LD EPS = 1e-9;
LL gcd (LL a, LL b) {while(b){a %= b;swap (a, b);}return a;} LL lcm(const LL a,const LL b){return a/gcd(a,b)*b;}LL sign(const LL x){return (x>0)-(x<0);}
template<class T>const T sqr(const T x){return x*x;}
template<class T> const T binpow(const T a, const ULL n, const T modulo){return n == 0 ? 1 : sqr ( binpow ( a, n/2, modulo ) ) % modulo * ( n % 2 ? a : 1 ) % modulo;}

const int MAXN = int(2e5)+42;
const LL MIND = 1LL - (LL)1e9;
const ULL KEY[2] = {2000000011, 2000000033};//int(1e9)+7;
int a[MAXN], b[MAXN];
int da[MAXN], db[MAXN];
ULL power_key[MAXN][2], prefix_hash_a[MAXN][2];

int main ( ) {
    ios::sync_with_stdio ( false );

	int n, w;
	cin >> n >> w;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = 0; i < w; i++){
		cin >> b[i];
	}
	for (int i = 0; i < n-1; i++){
		da[i] = a[i+1] - a[i];
	}
	for (int i = 0; i < w-1; i++){
		db[i] = b[i+1] - b[i];
	}
	for (int i = 0; i <= max(n,w); i++){
		for (int j = 0; j < 2; j++){
			power_key[i][j] = i == 0 ? 1 : power_key[i-1][j] * KEY[j];
		}
	}
	for (int i = 0; i < n-1; i++){
		for (int j = 0; j < 2; j++){
			prefix_hash_a[i][j] = LL ( da[i] - MIND ) * power_key[i][j] + ( i == 0 ? 0 : prefix_hash_a[i-1][j] );
		}
	}
	ULL hash_db[2] = {0,0};
	for (int i = 0; i < w-1; i++){
		for (int j = 0; j < 2; j++){
			hash_db[j]+= LL ( db[i] - MIND ) * power_key[i][j];
		}
	}
	int result = 0;
	for (int i = 0; i+w <= n; i++){
		LL hash[2];
		int checks = 0;
		for (int j = 0; j < 2; j++){
			hash[j] = prefix_hash_a[i+w-2][j];
			if ( i ) {
				hash[j] -= prefix_hash_a[i-1][j];
			}
			checks += hash[j] == hash_db[j] * power_key[i][j];
		}
		result += checks == 2;
	}
	cout << result << endl;

    return 0;
}


#include <iostream>

using namespace std;

const int MAXN = int(2e5);
const int MINA = 1;
const int MAXA = int(1e9);

int difference[2*MAXN], z[2*MAXN];

void read_tower(int difference_a[], const int n){
	int previous_a;
	cin >> previous_a;
	for (int i = 1; i < n; i++){
		int a;
		cin >> a;
		difference_a[i-1] = a - previous_a;
		previous_a = a;
	}
}

int main(){
	int n, w;
	cin >> n >> w;
	read_tower(difference+w, n);
	read_tower(difference, w);
	difference[w-1] = MAXA - MINA + 1;
	int left = 0, right = 0;
	int result = 0 == w-1;
	for (int i = 1; i < w+n-1; i++){
		z[i] = i > right ? 0 : min ( z[i - left], right - i + 1 );
		for ( ; i + z[i] < w+n-1 && difference[i+z[i]] == difference[z[i]]; ){
			++z[i];
		}
		if ( i + z[i] - 1 > right ) {
			left = i;
			right = i + z[i] - 1;
		}

		result += z[i] == w-1;
	}

	cout << result << endl;

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
#define MP make_pair
#define PB push_back
#define SZ(x) int((x).size())
#define SQR(x) (x)*(x)
#define SIGN(x) (x>1)-(x<0)
typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> pii; typedef pair<long,long> pll; typedef vector<int,int> vii;
const LD PI = 3.1415926535897932384626433832795L; const LD EPS = 1e-9;
LL gcd (LL a, LL b) {while(b){a %= b;swap (a, b);}return a;} LL lcm(const LL a,const LL b){return a/gcd(a,b)*b;}LL sign(const LL x){return (x>0)-(x<0);}
template<class T>const T sqr(const T x){return x*x;}
template<class T> const T binpow(const T a, const ULL n, const T modulo){return n == 0 ? 1 : sqr ( binpow ( a, n/2, modulo ) ) % modulo * ( n % 2 ? a : 1 ) % modulo;}

const int MAXN = int(2e5)+42;
const LL MIND = 1LL - (LL)1e9;
const ULL KEY = 2000000033;//int(1e9)+7;
int a[MAXN], b[MAXN];
int da[MAXN], db[MAXN];
ULL power_key[MAXN], prefix_hash_a[MAXN];

int main ( ) {
    ios::sync_with_stdio ( false );

	int n, w;
	cin >> n >> w;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = 0; i < w; i++){
		cin >> b[i];
	}
	for (int i = 0; i < n-1; i++){
		da[i] = a[i+1] - a[i];
	}
	for (int i = 0; i < w-1; i++){
		db[i] = b[i+1] - b[i];
	}
	power_key[0] = 1;
	for (int i = 1; i <= max(n,w); i++){
		power_key[i] = power_key[i-1] * KEY;
	}
	prefix_hash_a[0] = da[0] - MIND;
	for (int i = 1; i < n-1; i++){
		prefix_hash_a[i] = LL ( da[i] - MIND ) * power_key[i] + prefix_hash_a[i-1];
	}
	ULL hash_db = 0;
	for (int i = 0; i < w-1; i++){
		hash_db += LL ( db[i] - MIND ) * power_key[i];
	}
	int result = 0;
	for (int i = 0; i+w <= n; i++){
		LL hash = prefix_hash_a[i+w-2];
		if ( i ) hash -= prefix_hash_a[i-1];
		if ( hash == hash_db * power_key[i] ) {
			++result;
		}
	}
	cout << result << endl;

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
#define MP make_pair
#define PB push_back
#define SZ(x) int((x).size())
#define SQR(x) (x)*(x)
#define SIGN(x) (x>1)-(x<0)
typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> pii; typedef pair<long,long> pll; typedef vector<int,int> vii;
const LD PI = 3.1415926535897932384626433832795L; const LD EPS = 1e-9;
LL gcd (LL a, LL b) {while(b){a %= b;swap (a, b);}return a;} LL lcm(const LL a,const LL b){return a/gcd(a,b)*b;}LL sign(const LL x){return (x>0)-(x<0);}
template<class T>const T sqr(const T x){return x*x;}
template<class T> const T binpow(const T a, const ULL n, const T modulo){return n == 0 ? 1 : sqr ( binpow ( a, n/2, modulo ) ) % modulo * ( n % 2 ? a : 1 ) % modulo;}

const int MAXN = int(2e5)+42;
const LL MIND = 1LL - (LL)1e9;
const ULL KEY[2] = {2000000011, 2000000033};//int(1e9)+7;
int a[MAXN], b[MAXN];
int da[MAXN], db[MAXN];
ULL power_key[MAXN][2], prefix_hash_a[MAXN][2];

int main ( ) {
    ios::sync_with_stdio ( false );

	int n, w;
	cin >> n >> w;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = 0; i < w; i++){
		cin >> b[i];
	}
	for (int i = 0; i < n-1; i++){
		da[i] = a[i+1] - a[i];
	}
	for (int i = 0; i < w-1; i++){
		db[i] = b[i+1] - b[i];
	}
	for (int i = 0; i <= max(n,w); i++){
		for (int j = 0; j < 2; j++){
			power_key[i][j] = i == 0 ? 1 : power_key[i-1][j] * KEY[j];
		}
	}
	for (int i = 1; i < n-1; i++){
		for (int j = 0; j < 2; j++){
			prefix_hash_a[i][j] = LL ( da[i] - MIND ) * power_key[i][j] + ( i == 0 ? 0 : prefix_hash_a[i-1][j] );
		}
	}
	ULL hash_db[2] = {0,0};
	for (int i = 0; i < w-1; i++){
		for (int j = 0; j < 2; j++){
			hash_db [j]+= LL ( db[i] - MIND ) * power_key[i][j];
		}
	}
	int result = 0;
	for (int i = 0; i+w <= n; i++){
		LL hash[2];
		int checks = 0;
		for (int j = 0; j < 2; j++){
			hash[j] = prefix_hash_a[i+w-2][j];
			if ( i ) {
				hash[j] -= prefix_hash_a[i-1][j];
			}
			checks += hash[j] == hash_db[j] * power_key[i][j];
		}
		result += checks == 2;
	}
	cout << result << endl;

    return 0;
}


#include <iostream>

using namespace std;

const int MAXN = int(2e5);
const int MINA = 1;
const int MAXA = int(1e9);

int difference[2*MAXN], z[2*MAXN];

void read_tower(int difference_a[], const int n){
	int previous_a;
	cin >> previous_a;
	for (int i = 1; i < n; i++){
		int a;
		cin >> a;
		difference_a[i-1] = a - previous_a;
		previous_a = a;
	}
}

int main(){
	int n, w;
	cin >> n >> w;
	read_tower(difference+w, n);
	read_tower(difference, w);
	difference[w-1] = MAXA - MINA + 1;
	int left = 0, right = 0;
	int result = 0;
	for (int i = 1; i < w+n-1; i++){
		z[i] = i > right ? 0 : min ( z[i - left], right - i + 1 );
		for ( ; i + z[i] < w+n-1 && difference[i+z[i]] == difference[z[i]]; ){
			++z[i];
		}
		if ( i + z[i] - 1 > right ) {
			left = i;
			right = i + z[i] - 1;
		}

		result += z[i] == w-1;
	}

	cout << result << endl;

	return 0;
}