#include <iostream>
#include <set>
using namespace std;

int t, n, vis[200001];
string s;
set <int> a[2];
int main() {
	cin >> t;
	while(t--){
		cin >> n >> s;
		int ct = 0, mx = 0;
		for(int i = 0; i < n; ++i){
			if(s[i] == '0'){
				a[0].insert(i);
			}
			else{
				a[1].insert(i);
			}
		}
		while(!a[0].empty() && !a[1].empty()){
			++ct;
			if(*a[0].begin() < *a[1].begin()){
				auto it = a[0].begin();
				int c = 0;
				while(1){
					vis[*it] = ct;
					int d = *it;
					a[c].erase(it);
					it = a[!c].upper_bound(d);
					if(it == a[!c].end()){
						break;
					}
					c = !c;
				}
			}
			else{
				auto it = a[1].begin();
				int c = 1;
				while(1){
					vis[*it] = ct;
					int d = *it;
					a[c].erase(it);
					it = a[!c].upper_bound(d);
					if(it == a[!c].end()){
						break;
					}
					c = !c;
				}
			}
		}
		for(auto it = a[0].begin(); it != a[0].end(); ++it){
			++ct;
			vis[*it] = ct;
		}
		for(auto it = a[1].begin(); it != a[1].end(); ++it){
			++ct;
			vis[*it] = ct;
		}
		a[0].clear();
		a[1].clear();
		cout << ct << endl;
		for(int i = 0; i < n; ++i){
			cout << vis[i] << " ";
			vis[i] = 0;
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <set>
using namespace std;

int t, n, vis[200001];
string s;
set <int> a[2];
int main() {
	cin >> t;
	while(t--){
		cin >> n >> s;
		int ct = 0, mx = 0;
		for(int i = 0; i < n; ++i){
			if(s[i] == '0'){
				a[0].insert(i);
			}
			else{
				a[1].insert(i);
			}
		}
		while(a[0].size() && a[1].size()){
			++ct;
			while(vis[mx]){
				++mx;
			}
			if(*a[0].begin() < *a[1].begin()){
				auto it = a[0].begin();
				int c = 0;
				while(1){
					vis[*it] = ct;
					a[c].erase(it);
					it = a[!c].upper_bound(*it);
					if(it == a[!c].end()){
						break;
					}
					c = !c;
				}
			}
			else{
				auto it = a[1].begin();
				int c = 1;
				while(1){
					vis[*it] = ct;
					a[c].erase(it);
					it = a[!c].upper_bound(*it);
					if(it == a[!c].end()){
						break;
					}
					c = !c;
				}
			}
		}
		for(auto it = a[0].begin(); it != a[0].end(); ++it){
			++ct;
			vis[*it] = ct;
		}
		for(auto it = a[1].begin(); it != a[1].end(); ++it){
			++ct;
			vis[*it] = ct;
		}
		a[0].clear();
		a[1].clear();
		cout << ct << endl;
		for(int i = 0; i < n; ++i){
			cout << vis[i] << " ";
			vis[i] = 0;
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <set>
using namespace std;

int t, n, vis[200001];
string s;
set <int> a[2];
int main() {
	cin >> t;
	while(t--){
		cin >> n >> s;
		int ct = 0;
		for(int i = 0; i < n; ++i){
			if(s[i] == '0'){
				a[0].insert(i);
			}
			else{
				a[1].insert(i);
			}
		}
		while(!a[0].empty() && !a[1].empty()){
			++ct;
			if(*a[0].begin() < *a[1].begin()){
				auto it = a[0].begin();
				int c = 0;
				while(1){
					vis[*it] = ct;
					a[c].erase(it);
					it = a[!c].upper_bound(*it);
					if(it == a[!c].end()){
						break;
					}
					c = !c;
				}
			}
			else{
				auto it = a[1].begin();
				int c = 1;
				while(1){
					vis[*it] = ct;
					a[c].erase(it);
					it = a[!c].upper_bound(*it);
					if(it == a[!c].end()){
						break;
					}
					c = !c;
				}
			}
		}
		for(auto it = a[0].begin(); it != a[0].end(); ++it){
			++ct;
			vis[*it] = ct;
		}
		for(auto it = a[1].begin(); it != a[1].end(); ++it){
			++ct;
			vis[*it] = ct;
		}
		a[0].clear();
		a[1].clear();
		cout << ct << endl;
		for(int i = 0; i < n; ++i){
			cout << vis[i] << " ";
			vis[i] = 0;
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <set>
using namespace std;

int t, n, vis[200001];
string s;
set <int> a[2];
int main() {
	cin >> t;
	while(t--){
		cin >> n >> s;
		int ct = 0, mx = 0;
		for(int i = 0; i < n; ++i){
			if(s[i] == '0'){
				a[0].insert(i);
			}
			else{
				a[1].insert(i);
			}
		}
		while(!a[0].empty() && !a[1].empty()){
			++ct;
			if(*a[0].begin() < *a[1].begin()){
				auto it = a[0].begin();
				int c = 0;
				while(1){
					vis[*it] = ct;
					a[c].erase(it);
					it = a[!c].upper_bound(*it);
					if(it == a[!c].end()){
						break;
					}
					c = !c;
				}
			}
			else{
				auto it = a[1].begin();
				int c = 1;
				while(1){
					vis[*it] = ct;
					a[c].erase(it);
					it = a[!c].upper_bound(*it);
					if(it == a[!c].end()){
						break;
					}
					c = !c;
				}
			}
		}
		for(auto it = a[0].begin(); it != a[0].end() && a[0].size(); ++it){
			++ct;
			vis[*it] = ct;
		}
		for(auto it = a[1].begin(); it != a[1].end() && a[1].size(); ++it){
			++ct;
			vis[*it] = ct;
		}
		a[0].clear();
		a[1].clear();
		cout << ct << endl;
		for(int i = 0; i < n; ++i){
			cout << vis[i] << " ";
			vis[i] = 0;
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <set>
using namespace std;

int t, n, vis[200001];
string s;
set <int> a[2];
int main() {
	cin >> t;
	while(t--){
		cin >> n >> s;
		int ct = 0, mx = 0;
		for(int i = 0; i < n; ++i){
			if(s[i] == '0'){
				a[0].insert(i);
			}
			else{
				a[1].insert(i);
			}
		}
		while(a[0].size() && a[1].size()){
			++ct;
			while(vis[mx]){
				++mx;
			}
			if(*a[0].begin() < *a[1].begin()){
				auto it = a[0].begin();
				int c = 0;
				while(1){
					vis[*it] = ct;
					a[c].erase(it);
					if(a[!c].upper_bound(*it) == a[!c].end()){
						break;
					}
					it = a[!c].upper_bound(*it);
					c = !c;
				}
			}
			else{
				auto it = a[1].begin();
				int c = 1;
				while(1){
					vis[*it] = ct;
					a[c].erase(it);
					if(a[!c].upper_bound(*it) == a[!c].end()){
						break;
					}
					it = a[!c].upper_bound(*it);
					c = !c;
				}
			}
		}
		for(auto it = a[0].begin(); it != a[0].end(); ++it){
			++ct;
			vis[*it] = ct;
		}
		for(auto it = a[1].begin(); it != a[1].end(); ++it){
			++ct;
			vis[*it] = ct;
		}
		a[0].clear();
		a[1].clear();
		cout << ct << endl;
		for(int i = 0; i < n; ++i){
			cout << vis[i] << " ";
			vis[i] = 0;
		}
		cout << endl;
	}
	return 0;
}


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

typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int n;
vector<int>prime;

void sieve(int n)
{
    prime[1] = 1;
    prime[2] = 1;
    for(int i=3;i<=n;i+=2)
        prime[i] = 1;
    for (int p=3; p*p<=n; p+=2)
    {
        if (prime[p] == 1)
        {
            for (int i=p*p; i<=n; i += 2*p)
                prime[i] = 0;
        }
    }
}

int main(){
  n=1000005;
  prime=vector<int>(n+1);
  sieve(n);
  prime[0]=0;
  for(int i=1;i<n;i++)
       prime[i] += prime[i-1];

  int t;
  cin>>t;
  for(int i=0;i<t;i++){
      cin>>n;
      int m = sqrt(n);
      cout<<prime[n]-prime[m]+1<<"\n";
  }

return 0;

}


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

typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int n;
vector<char>is_prime;

void sieve(){
    for (int i = 2; i <= n; i++) {
        if (is_prime[i] && (long long)i * i <= n) {
            for (int j = i * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
}

int main(){
  n=1000005;
  is_prime=vector<char>(n+1);
  is_prime.assign(n+1,true);
  is_prime[0] = is_prime[1] = false;
  sieve();
  vector<int>a(n);
  a.assign(n,0);
  a[0]=1;

  for(int i=1;i<n;i++){
      if(is_prime[i])a[i]++;
      a[i]+=a[i-1];
  }

  int t;
  cin>>t;
  for(int i=0;i<t;i++){
      int m;cin>>m;
      cout<<a[m]-a[sqrt(m)]+1<<"\n";
  }

return 0;

}


#include <bits/stdc++.h>
using namespace std;
int prime[1000009];
void sieve(int n)
{
    prime[1] = 1;
    prime[2] = 1;
    for(int i=3;i<=n;i+=2)
        prime[i] = 1;
    for (int p=3; p*p<=n; p+=2)
    {
        if (prime[p] == 1)
        {
            for (int i=p*p; i<=n; i += 2*p)
                prime[i] = 0;
        }
    }
}

int main()
{
    sieve(1000005);
    for(int i=1;i<=1000005;i++)
       prime[i] += prime[i-1];

    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int m = sqrt(n);
        //cout<<prime[n]-prime[m]+1<<endl;
        printf("%d\n",prime[n]-prime[m]+1);
    }
    return 0;
}


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

typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int n;
vector<int>prime;

void sieve(int n)
{
    prime[1] = 1;
    prime[2] = 1;
    for(int i=3;i<=n;i+=2)
        prime[i] = 1;
    for (int p=3; p*p<=n; p+=2)
    {
        if (prime[p] == 1)
        {
            for (int i=p*p; i<=n; i += 2*p)
                prime[i] = 0;
        }
    }
}

int main(){
  n=1000005;
  prime=vector<int>(n+1);
  sieve(n);
  prime[0]=0;
  for(int i=1;i<n;i++)
       prime[i] += prime[i-1];

  int t;
  cin>>t;
  for(int i=0;i<t;i++){
      scanf("%d",&n);
      int m = sqrt(n);
      printf("%d\n",prime[n]-prime[m]+1);
  }

return 0;

}


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

typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int n;
vector<int>prime;

void sieve(int n)
{
    prime[1] = 1;
    prime[2] = 1;
    for(int i=3;i<=n;i+=2)
        prime[i] = 1;
    for (int p=3; p*p<=n; p+=2)
    {
        if (prime[p] == 1)
        {
            for (int i=p*p; i<=n; i += 2*p)
                prime[i] = 0;
        }
    }
}

int main(){
  n=1000005;
  prime=vector<int>(n+1);
  sieve(n);
  vector<int>a(n);
  a.assign(n,0);
  a[0]=1;
  for(int i=1;i<n;i++){
      if(prime[i])a[i]++;
      a[i]+=a[i-1];
  }

  int t;
  cin>>t;
  for(int i=0;i<t;i++){
      int m;
      cin>>m;
      cout<<a[m]-a[sqrt(m)]+1<<"\n";
  }

return 0;

}


#pragma GCC optimize("Ofast")  // remove in mingw32 bit ;
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define double long double
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN

using namespace std;

#ifdef CUST_DEBUG
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.F<<','<<p.S<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p){return cout<<"("<<p.F<<", "<<p.S<<")";}
template<typename A> ostream& operator<<(ostream &cout,vector<A> const &v){cout<<"[";for(int i=0;i<v.size();i++){if(i)cout<<", ";cout<<v[i];}return cout<<"]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p){cin>>p.F;return cin>>p.S;}
#endif

const long long MAXN = 1e6 + 7;

template<long long SZ> struct Sieve {
	bitset<SZ> pri;
	vector<long long> pr;
	Sieve() {
		pri.set();
		pri[0] = pri[1] = 0;
		for (int i = 4; i < SZ; i += 2) {
			pri[i] = 0;
		}
		for (int i = 3; i * i < SZ; i += 2) {
			if (pri[i]) {
				for (int j = i * i; j < SZ; j += 2 * i) {
					pri[j] = 0;
				}
			}
		}
		for (int i = 2; i < SZ; i++) {
			if (pri[i]) {
				pr.push_back(i);
			}
		}
	}
};

int32_t main(){
	#ifndef CUST_DEBUG
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	// cin.exceptions(cin.Failbit);
	int t = 1;
	cin >> t;
	Sieve<MAXN> Si;
	ll a[MAXN] = {0};
	for(ll i = 1 ;i < MAXN ;i++){
		if(Si.pri[i])a[i]++;
		a[i] += a[i-1];
	}
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		ll n;
		cin >> n;
		cout << a[n] - a[(ll)sqrt(n)] + 1<<"\n";
	}
	return 0;
}


#pragma GCC optimize("Ofast")  // remove in mingw32 bit ;
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define double long double
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN

using namespace std;

#ifdef CUST_DEBUG
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.F<<','<<p.S<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p){return cout<<"("<<p.F<<", "<<p.S<<")";}
template<typename A> ostream& operator<<(ostream &cout,vector<A> const &v){cout<<"[";for(int i=0;i<v.size();i++){if(i)cout<<", ";cout<<v[i];}return cout<<"]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p){cin>>p.F;return cin>>p.S;}
#endif

const long long MAXN = 1e6 + 7;

template<long long SZ> struct Sieve {
	bitset<SZ> pri;
	vector<long long> pr;
	Sieve() {
		pri.set();
		pri[0] = pri[1] = 0;
		for (int i = 4; i < SZ; i += 2) {
			pri[i] = 0;
		}
		for (int i = 3; i * i < SZ; i += 2) {
			if (pri[i]) {
				for (int j = i * i; j < SZ; j += 2 * i) {
					pri[j] = 0;
				}
			}
		}
		for (int i = 2; i < SZ; i++) {
			if (pri[i]) {
				pr.push_back(i);
			}
		}
	}
};

int32_t main(){
	#ifndef CUST_DEBUG
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	// cin.exceptions(cin.Failbit);
	int t = 1;
	cin >> t;
	Sieve<MAXN> Si;
	ll a[MAXN] = {0};
	for(ll i = 1 ;i+1 < MAXN ;i++){
		if(Si.pri[i])a[i]++ ,a[min(i*i ,MAXN-5) + 1]--;
		a[i] += a[i-1];
	}
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		ll n;
		cin >> n;
		cout << a[n] + 1<<"\n";
	}
	return 0;
}


#pragma GCC optimize("Ofast")  // remove in mingw32 bit ;
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define double long double
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN

using namespace std;

#ifdef CUST_DEBUG
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.F<<','<<p.S<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p){return cout<<"("<<p.F<<", "<<p.S<<")";}
template<typename A> ostream& operator<<(ostream &cout,vector<A> const &v){cout<<"[";for(int i=0;i<v.size();i++){if(i)cout<<", ";cout<<v[i];}return cout<<"]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p){cin>>p.F;return cin>>p.S;}
#endif

const long long MAXN = 1e6 + 7;

template<long long SZ> struct Sieve {
	bitset<SZ> pri;
	vector<long long> pr;
	Sieve() {
		pri.set();
		pri[0] = pri[1] = 0;
		for (int i = 4; i < SZ; i += 2) {
			pri[i] = 0;
		}
		for (int i = 3; i * i < SZ; i += 2) {
			if (pri[i]) {
				for (int j = i * i; j < SZ; j += 2 * i) {
					pri[j] = 0;
				}
			}
		}
		for (int i = 2; i < SZ; i++) {
			if (pri[i]) {
				pr.push_back(i);
			}
		}
	}
};

int32_t main(){
	#ifndef CUST_DEBUG
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	// cin.exceptions(cin.Failbit);
	int t = 1;
	cin >> t;
	Sieve<MAXN> Si;
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		ll n ,ans = 1;
		cin >> n;
		for(ll &pr : Si.pr){
		    if(pr > n)break;
			if(pr*pr > n)ans++;
		}
		cout << ans<<"\n";
	}
	return 0;
}


#pragma GCC optimize("Ofast")  // remove in mingw32 bit ;
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define double long double
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN

using namespace std;

#ifdef CUST_DEBUG
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.F<<','<<p.S<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p){return cout<<"("<<p.F<<", "<<p.S<<")";}
template<typename A> ostream& operator<<(ostream &cout,vector<A> const &v){cout<<"[";for(int i=0;i<v.size();i++){if(i)cout<<", ";cout<<v[i];}return cout<<"]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p){cin>>p.F;return cin>>p.S;}
#endif

const long long MAXN = 1e6 + 7;

template<long long SZ> struct Sieve {
	bitset<SZ> pri;
	vector<long long> pr;
	Sieve() {
		pri.set();
		pri[0] = pri[1] = 0;
		for (int i = 4; i < SZ; i += 2) {
			pri[i] = 0;
		}
		for (int i = 3; i * i < SZ; i += 2) {
			if (pri[i]) {
				for (int j = i * i; j < SZ; j += 2 * i) {
					pri[j] = 0;
				}
			}
		}
		for (int i = 2; i < SZ; i++) {
			if (pri[i]) {
				pr.push_back(i);
			}
		}
	}
};

int32_t main(){
	#ifndef CUST_DEBUG
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	// cin.exceptions(cin.Failbit);
	int t = 1;
	cin >> t;
	Sieve<MAXN> Si;
	ll a[MAXN] = {0};
	for(ll i = 1 ;i < MAXN ;i++){
		if(Si.pri[i])a[i]++ ,a[min(i*i ,MAXN-1) + 1]--;
		a[i] += a[i-1];
	}
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		ll n;
		cin >> n;
		cout << a[n] + 1<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define IOS; ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb emplace_back
#define pi pair<int,int>
#define fi first
#define se second
#define INF 2147483647
using namespace std;
int min(int a,int b) {return a<b?a:b;}
int max(int a,int b) {return a>b?a:b;}
int n,m;
bool isprime[1000005];
set<int> st;
void f()
{
	fill(isprime,isprime+1000005,1);
	isprime[1]=1;
	for (int i=2;i<=1000005;i++)
		if (isprime[i])
		{
			st.insert(i);
			for (int j=i*i;j<=1000005;j+=i)
				isprime[j]=0;
		}
}
int dp[1000005];
void sol()
{
	dp[1]=1;dp[2]=2;dp[3]=3;
	for (int i=4;i<=1000004;i++)
	{
		int sq=sqrt(i);
		if (sq*sq==i)
		{
			if (st.find(sq)!=st.end())
				dp[i]=dp[i-1]-1;
			else
				dp[i]=dp[i-1];
		}
		else if (st.find(i)!=st.end())
		{
			dp[i]=dp[i-1]+1;
		}
		else
		{
			dp[i]=dp[i-1];
		}
	}
}
int32_t main(){
	IOS;
	int t,n;
	cin >>t;
	f();
	sol();
	while (t--)
	{
		cin >>n;
		cout <<dp[n]<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define IOS; ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb emplace_back
#define pi pair<int,int>
#define fi first
#define se second
#define INF 2147483647
using namespace std;
int min(int a,int b) {return a<b?a:b;}
int max(int a,int b) {return a>b?a:b;}
int n,m;
bool isprime[1000005];
vector<int> p;
void f()
{
	fill(isprime,isprime+1000005,1);
	isprime[1]=1;
	for (int i=2;i<=1000005;i++)
		if (isprime[i])
		{
			p.pb(i);
			for (int j=i*i;j<=1000005;j+=i)
				isprime[j]=0;
		}
}
int32_t main(){
	IOS;
	int t,n;
	cin >>t;
	f();
	while (t--)
	{
		cin >>n;
		int sq=sqrt(n);
		int ans=(lower_bound(p.begin(),p.end(),n)-p.begin())-(lower_bound(p.begin(),p.end(),sq)-p.begin());
		cout <<ans+(isprime[n]==1)<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define IOS; ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb emplace_back
#define pi pair<int,int>
#define fi first
#define se second
#define INF 2147483647
using namespace std;
int min(int a,int b) {return a<b?a:b;}
int max(int a,int b) {return a>b?a:b;}
int n,m;
bool isprime[1000005];
set<int> st;
void f()
{
	fill(isprime,isprime+1000005,1);
	isprime[1]=1;
	for (int i=2;i<=1000005;i++)
		if (isprime[i])
		{
			st.insert(i);
			for (int j=i*i;j<=1000005;j+=i)
				isprime[j]=0;
		}
}
int dp[1000005];
void sol()
{
	dp[1]=1;dp[2]=2;dp[3]=3;
	for (int i=4;i<=1000004;i++)
	{
		int sq=sqrt(i);
		if (sq*sq==i)
		{
			if (st.find(sq)!=st.end())
				dp[i]=dp[i-1]-1;
			else
				dp[i]=dp[i-1];
		}
		else if (st.find(i)!=st.end())
		{
			dp[i]=dp[i-1]+1;
		}
		else
		{
			dp[i]=dp[i-1];
		}
	}
}
int32_t main(){
	//IOS;
	int t,n;
	cin >>t;
	f();
	sol();
	while (t--)
	{
		cin >>n;
		cout <<dp[n]<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define IOS; ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb emplace_back
#define pi pair<int,int>
#define fi first
#define se second
#define INF 2147483647
using namespace std;
int min(int a,int b) {return a<b?a:b;}
int max(int a,int b) {return a>b?a:b;}
int n,m;
bool isprime[1000005];
set<int> st;
void f()
{
	fill(isprime,isprime+1000005,1);
	isprime[1]=1;
	for (int i=2;i<=1000005;i++)
		if (isprime[i])
		{
			st.insert(i);
			for (int j=i*i;j<=1000005;j+=i)
				isprime[j]=0;
		}
}
int dp[1000005];
void sol()
{
	dp[1]=1;dp[2]=2;dp[3]=3;
	for (int i=4;i<=1000004;i++)
	{
		int sq=sqrt(i);
		if (sq*sq==i)
		{
			dp[i]=dp[i-1]-1;
		}
		else if (st.find(i)!=st.end())
		{
			dp[i]=dp[i-1]+1;
		}
		else
		{
			dp[i]=dp[i-1];
		}
	}
}
int32_t main(){
	IOS;
	int t,n;
	cin >>t;
	f();
	sol();
	while (t--)
	{
		cin >>n;
		cout <<dp[n]<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long int
//#define int double
#define f(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mod 1000000007
using namespace std;

int32_t main(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t;
cin>>t;
vector<int>v(1e6+5,0);
vector<int>p;
for(int i=2;i<=1e6;i++){
	if(v[i]==0)p.pb(i);
	for(int j=2*i;j<=1e6;j+=i){
		v[j]=1;
	}
}
while(t--){
	int n;
	cin>>n;
	int ans=1;
	int x=sqrt(n);
	auto it=upper_bound(p.begin(),p.end(),x);
	auto jt=upper_bound(p.begin(),p.end(),n);
	int yy=jt-p.begin();
	int y=it-p.begin();
	cout<<yy-y<<endl;
}

return 0;
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,n) for(int i=0;i<n;i++)
#define lop(i,a,b) for(int i=a;i<=b;i++)
#define int long long int
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp make_pair
#define sz(a) int((a).size())
#define pb push_back
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define so(v) sort(all(v))
#define sod(v) sort(allr(v))
#define mfind(c, element) (c.find(element) != c.end())
#define gfind(c, element) (find(all(c),element) != c.end())
#define gfindindex(c, element) (find(all(c),element)-c.begin())
#define vp(x) cout << #x << " --> " << x << endl;
#define cp1(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define cpp1(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define ccp1(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define bsnp np3(low,high,mid);
#define hmm1 high=mid-1;
#define lmp1 low=mid+1;
#define hmp1 high=mid+1;
#define lmm1 low=mid-1;
#define fi first
#define se second
#define endl "\n"
#define np1(x) cout<<#x<<"="<<x<<'\n'
#define np2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define np3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};//comparison used for sorting set<pair<i,i>,cmp>
bool myComparison(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
//increasing ordr basedd on 2nd
};
const int MAX=1e6;
vector<bool> isPrime(MAX+1,true);
void SetPrime(int MAX)
{
    isPrime[0] = false;
    isPrime[1] = false;
    for(int i = 2; i * i <= MAX; ++i)
	{
        if(isPrime[i] == true)
		{
            for(int j = i * i; j <= MAX ;j += i)
                isPrime[j] = false;
        }
    }
}
main()
{
IOS;
SetPrime(MAX);
vi pref(MAX);
lop(i,1,MAX)
if(isPrime[i])
pref[i]=1;
else
pref[i]=0;

for(int i=2;i<MAX;i++)
pref[i]+=pref[i-1];

int t;cin>>t;
while(t--)
{
    int n;
    cin>>n;
    int z=sqrt(n);
if(z*z==n) z--;
 //   np2(z,n);
 //   np2(pref[z],pref[n]);
    cout<<pref[n]-pref[z]+1<<endl;

}

return 0;
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,n) for(int i=0;i<n;i++)
#define lop(i,a,b) for(int i=a;i<=b;i++)
#define int long long int
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp make_pair
#define sz(a) int((a).size())
#define pb push_back
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define so(v) sort(all(v))
#define sod(v) sort(allr(v))
#define mfind(c, element) (c.find(element) != c.end())
#define gfind(c, element) (find(all(c),element) != c.end())
#define gfindindex(c, element) (find(all(c),element)-c.begin())
#define vp(x) cout << #x << " --> " << x << endl;
#define cp1(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define cpp1(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define ccp1(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define bsnp np3(low,high,mid);
#define hmm1 high=mid-1;
#define lmp1 low=mid+1;
#define hmp1 high=mid+1;
#define lmm1 low=mid-1;
#define fi first
#define se second
#define endl "\n"
#define np1(x) cout<<#x<<"="<<x<<'\n'
#define np2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define np3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};//comparison used for sorting set<pair<i,i>,cmp>
bool myComparison(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
//increasing ordr basedd on 2nd
};
const int MAX=1e6;
vector<bool> isPrime(MAX+1,true);
void SetPrime(int MAX)
{
    isPrime[0] = false;
    isPrime[1] = false;
    for(int i = 2; i * i <= MAX; ++i)
	{
        if(isPrime[i] == true)
		{
            for(int j = i * i; j <= MAX ;j += i)
                isPrime[j] = false;
        }
    }
}
main()
{
IOS;
SetPrime(MAX);
int t;
cin>>t;
vector<int>v(1e6+5,0);
vector<int>vv(1e6+5,0);
vector<int>p;int in=0;
for(int i=2;i<=1e6;i++){
	if(isPrime[i]){p.pb(i);in++;}
	vv[i]=in;
}

while(t--){
	int n;
	cin>>n;
	int ans=1;
	int x=sqrt(n);
	//auto it=upper_bound(p.begin(),p.end(),x);
	//auto jt=upper_bound(p.begin(),p.end(),n);
	int yy=vv[n]-vv[x];

	cout<<yy+1<<endl;
}

return 0;
}


#include<bits/stdc++.h>
#define int long long int
//#define int double
#define f(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mod 1000000007
using namespace std;

int32_t main(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t;
cin>>t;
vector<int>v(1e6+5,0);
//vector<int>vv(1e6+5,0);
vector<int>p;int in=0;
for(int i=2;i<=1e6;i++){
	if(v[i]==0){p.pb(i);in++;}
	v[i]=in;
	for(int j=2*i;j<=1e6;j+=i){
		v[j]=1;
	}
}

while(t--){
	int n;
	cin>>n;
	int ans=1;
	int x=sqrt(n);
	int yy=v[n]-v[x];

	cout<<yy+1<<endl;
}

return 0;
}


#include<bits/stdc++.h>
#define int long long int
//#define int double
#define f(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mod 1000000007
using namespace std;

int32_t main(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t;
cin>>t;
vector<int>v(1e6+5,0);
vector<int>p;
for(int i=2;i<=1e6;i++){
	if(v[i]==0)p.pb(i);
	for(int j=2*i;j<=1e6;j+=i){
		v[j]=1;
	}
}
while(t--){
	int n;
	cin>>n;
	int ans=1;
	int x=sqrt(n);
	auto it=upper_bound(p.begin(),p.end(),x);
	auto jt=upper_bound(p.begin(),p.end(),n);
	int yy=jt-p.begin();
	int y=it-p.begin();
	cout<<yy-y+1<<endl;
}

return 0;
}


#include<bits/stdc++.h>
#define int long long int
//#define int double
#define f(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mod 1000000007
using namespace std;

int32_t main(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t;
cin>>t;
vector<int>v(1e6+5,0);
vector<int>p;
for(int i=2;i<=1e6;i++){
	if(v[i]==0)p.pb(i);
	for(int j=2*i;j<=1e6;j+=i){
		v[j]=1;
	}
}
while(t--){
	int n;
	cin>>n;
	int ans=1;
	int x=sqrt(n);
	auto it=upper_bound(p.begin(),p.end(),x);
	int y=it-p.begin();
	cout<<p.size()-y<<endl;
}

return 0;
}