#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

ll n, q, x, t, cnt2, cnt, res, a[200007], prime[500], used[5000007], num[500007], ans;

int main () {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    	scanf ("%I64d", &a[i]);
    for (int i = 1; i <= q; i++) {
    	scanf ("%I64d", &t);
    	if (a[t] == 1) {
    		if(used[t])
    			ans -= cnt2 - 1ll, cnt2 --;
    		else
    			ans += cnt2, cnt2 ++;
    		used[t]=!used[t];
    		printf("%d\n", ans);
    		continue;
    	}
    	x = a[t], cnt = 0, res = 0;
    	for(int j = 2; j * j <= x; j++) {
    		if (x % j == 0)
    			prime[cnt++] = j;
    		while (x % j == 0)
    			x = x / j;
    	}
    	if (x > 1)
    		prime[cnt++] = x;
    	for (int mask = 1; mask < 1 << cnt; mask++) {
    		ll r = 1, kol = 0;
    		for (int j = 0; j < cnt; j++) {
    			if (mask & 1 << j) {
    				r = r * prime[j];
    				kol ++;
    			}
    		}
    		if (kol % 2)
    			res += num[r];
    		else
    			res -= num[r];
    		if (used[t]) num[r] --;
    		else num[r] ++;
    	}
    	if (used[t])
    		ans -= cnt2 - res, cnt2 --;
    	else
    		ans += cnt2 - res, cnt2 ++;
    	used[t]=!used[t];
    	printf("%I64d\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

ll n, q, x, t, cnt2, cnt, res, a[200007], prime[500], used[5000007], num[500007], ans;

int main () {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    	scanf ("%d", &a[i]);
    for (int i = 1; i <= q; i++) {
    	scanf ("%d", &t);
    	if (a[t] == 1) {
    		if(used[t])
    			ans -= cnt2 - 1, cnt2 --;
    		else
    			ans += cnt2, cnt2 ++;
    		used[t]=!used[t];
    		printf("%d\n", ans);
    		continue;
    	}
    	x = a[t], cnt = 0, res = 0;
    	for(int j = 2; j * j <= x; j++) {
    		if (x % j == 0)
    			prime[cnt++] = j;
    		while (x % j == 0)
    			x = x / j;
    	}
    	if (x > 1)
    		prime[cnt++] = x;
    	for (int mask = 1; mask < 1 << cnt; mask++) {
    		int r = 1, kol = 0;
    		for (int j = 0; j < cnt; j++) {
    			if (mask & 1 << j) {
    				r = r * prime[j];
    				kol ++;
    			}
    		}
    		if (kol % 2) {
    			res += num[r];
    			if (used[t]) res --;
    		}
    		else {
    			res -= num[r];
    			if (used[t]) res ++;
    		}
    		if (used[t]) num[r] --;
    		else num[r] ++;
    	}
    	if (used[t])
    		ans -= cnt2 - res, cnt2 --;
    	else
    		ans += cnt2 - res, cnt2 ++;
    	used[t]=!used[t];
    	printf("%I64d\n", ans);
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

#define f first
#define s second
#define mk make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define sqr(x) (x) * (x)
#define forn(i, l, r) for(int i = l; i < r; i ++)
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)
#define y1 salnk
#define sz 400100

const int inf = (int)1e9;
const int mod = inf + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;
int n, q, a[sz], N;
int ans;
int id, w[sz], koef, num, mp[sz], cnut;
vector <int> primes;

int main () {
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for (int i = 1; i <= q; i++) {
        scanf("%d", &id);
        num = a[id];
        int pop = 0;
            primes.clear();
            for (int j = 2; j * j <= num; j++)
                if (num % j == 0) {
                    primes.pb(j);
                    while (num % j == 0) num /= j;
                }
            if (num > 1) primes.pb(num);
            int N = primes.size();
            for (int mask = 1; mask < (1 << N); mask++) {
                int cnt = 0, um = 1;
                for (int j = 0; j < N; j++)
                    if (mask & (1 << j)) {
                        um = um * primes[j];
                        cnt++;
                    }
                if (cnt & 1)
                    pop += mp[um];
                else
                    pop -= mp[um];
                if (w[id]) mp[um]--; else mp[um]++;
            }

            if (w[id]) ans -= cnut - pop; else ans += cnut-pop;
            if (!w[id]) cnut++;  else cnut--;

            w[id] = 1-w[id];
            printf("%d\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

ll n, q, x, t, cnt2, cnt, res, a[200007], prime[500], used[5000007], num[500007], ans;

int main () {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    	scanf ("%d", &a[i]);
    for (int i = 1; i <= q; i++) {
    	scanf ("%d", &t);
    	x = a[t], cnt = 0, res = 0;
    	for(int j = 2; j * j <= x; j++) {
    		if (x % j == 0)
    			prime[cnt++] = j;
    		while (x % j == 0)
    			x = x / j;
    	}
    	if (x > 1)
    		prime[cnt++] = x;
    	for (int mask = 1; mask < 1 << cnt; mask++) {
    		int r = 1, kol = 0;
    		for (int j = 0; j < cnt; j++) {
    			if (mask & 1 << j) {
    				r = r * prime[j];
    				kol ++;
    			}
    		}
    		if (kol % 2)
    			res += num[r];
    		else
    			res -= num[r];
    		if (used[t]) num[r] --;
    		else num[r] ++;
    	}
    	if (used[t])
    		ans -= cnt2 - res - 1, cnt2 --;
    	else
    		ans += cnt2 - res, cnt2 ++;
    	used[t]=!used[t];
    	printf("%I64d\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

ll n, q, x, t, cnt2, cnt, res, a[200007], prime[500], used[5000007], num[500007], ans;

int main () {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    	scanf ("%I64d", &a[i]);
    for (int i = 1; i <= q; i++) {
    	scanf ("%I64d", &t);
    	if (a[t] == 1) {
    		if(used[t])
    			ans -= cnt2 - 1ll, cnt2 --;
    		else
    			ans += cnt2, cnt2 ++;
    		used[t]=!used[t];
    		printf("%I64d\n", ans);
    		continue;
    	}
    	x = a[t], cnt = 0, res = 0;
    	for(int j = 2; j * j <= x; j++) {
    		if (x % j == 0)
    			prime[cnt++] = j;
    		while (x % j == 0)
    			x = x / j;
    	}
    	if (x > 1)
    		prime[cnt++] = x;
    	for (int mask = 1; mask < 1 << cnt; mask++) {
    		ll r = 1, kol = 0;
    		for (int j = 0; j < cnt; j++) {
    			if (mask & 1 << j) {
    				r = r * prime[j];
    				kol ++;
    			}
    		}
    		if (kol % 2)
    			res += num[r];
    		else
    			res -= num[r];
    		if (used[t]) num[r] --;
    		else num[r] ++;
    	}
    	if (used[t])
    		ans -= cnt2 - res, cnt2 --;
    	else
    		ans += cnt2 - res, cnt2 ++;
    	used[t]=!used[t];
    	printf("%I64d\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

ll n, q, x, t, cnt2, cnt, res, a[200007], prime[500], used[5000007], num[500007], ans;

int main () {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    	scanf ("%d", &a[i]);
    for (int i = 1; i <= q; i++) {
    	scanf ("%d", &t);
    	if (a[t] == 1) {
    		if(used[t])
    			ans -= cnt2 - 1, cnt2 --;
    		else
    			ans += cnt2, cnt2 ++;
    		used[t]=!used[t];
    		printf("%d\n", ans);
    		continue;
    	}
    	x = a[t], cnt = 0, res = 0;
    	for(int j = 2; j * j <= x; j++) {
    		if (x % j == 0)
    			prime[cnt++] = j;
    		while (x % j == 0)
    			x = x / j;
    	}
    	if (x > 1)
    		prime[cnt++] = x;
    	for (int mask = 1; mask < 1 << cnt; mask++) {
    		int r = 1, kol = 0;
    		for (int j = 0; j < cnt; j++) {
    			if (mask & 1 << j) {
    				r = r * prime[j];
    				kol ++;
    			}
    		}
    		if (kol % 2) {
    			res += num[r];
    			//if (used[t]) res --;
    		}
    		else {
    			res -= num[r];
    			//if (used[t]) res ++;
    		}
    		if (used[t]) num[r] --;
    		else num[r] ++;
    	}
    	if (used[t])
    		ans -= cnt2 - res, cnt2 --;
    	else
    		ans += cnt2 - res, cnt2 ++;
    	used[t]=!used[t];
    	printf("%I64d\n", ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%lld",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
ll arr[200005],sel[200005],val[500005];
vector<int>v[500005];
ll power[10];
int main()
{
	ll i,j,k,n,q;
	sd(n);
	sd(q);
	for(i=1;i<=n;i++)
		sd(arr[i]);
	power[0]=1;
	for(i=1;i<10;i++)
		power[i]=2*power[i-1];
	for(i=2;i<=500000;i++)
	{
		if(v[i].empty())
		{
			for(j=i;j<=500000;j+=i)
			{
				v[j].pb(i);
			}
		}
	}
	ll tot=0;
	while(q--)
	{
		sd(i);
		//j=arr[i];
		k=power[v[arr[i]].size()];
		if(sel[i]==1)
		{
			for(j=0;j<k;j++)
			{
				ll temp=1,temp2=j,x=0;
				while(temp2!=0)
				{
					if(temp2%2==1)
					{
						temp*=v[arr[i]][x];
					}
					temp2/=2;
					x++;
				}
				val[temp]--;
			}
		}
		ll ans=0;
		for(j=0;j<k;j++)
		{
			ll temp=1,temp2=j,x=0,y=0;
			while(temp2!=0)
			{
				if(temp2%2==1)
				{
					temp*=v[arr[i]][x];
					y++;
				}
				x++;
				temp2/=2;
			}
			if(y%2==0)
			{
				ans+=val[temp];
			}
			else
				ans-=val[temp];
			if(sel[i]==0)
				val[temp]++;
			//cout<<j<<" "<<temp<<" "<<endl;
		}
		if(sel[i]==0){
			tot+=ans;
		}
		else
			tot-=ans;
		sel[i]=1-sel[i];
		printf("%lld\n",tot );
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
int arr[200005],sel[200005],val[500005];
vector<int>v[500005];
int power[10];
int main()
{
	int i,j,k,n,q;
	sd(n);
	sd(q);
	for(i=1;i<=n;i++)
		sd(arr[i]);
	power[0]=1;
	for(i=1;i<10;i++)
		power[i]=2*power[i-1];
	for(i=2;i<=500000;i++)
	{
		if(v[i].empty())
		{
			for(j=i;j<=500000;j+=i)
			{
				v[j].pb(i);
			}
		}
	}
	int tot=0;
	while(q--)
	{
		sd(i);
		//j=arr[i];
		k=power[v[arr[i]].size()];
		int ans=0;
		for(j=0;j<k;j++)
		{
			int temp=1,temp2=j,x=0,y=0;
			while(temp2!=0)
			{
				if(temp2%2==1)
				{
					temp*=v[arr[i]][x];
					y++;
				}
				x++;
				temp2/=2;
			}
			if(y%2==0)
			{
				ans+=val[temp];
			}
			else
				ans-=val[temp];
			if(sel[i]==0)
				val[temp]++;
			else
				val[temp]--;
			//cout<<j<<" "<<temp<<" "<<endl;
		}
		int pro=1;
		for(j=0;j<v[arr[i]].size();j++)
			pro*=v[arr[i]][j];
		if(sel[i]==0)
			tot+=ans;
		else if(pro==arr[i])
			tot-=ans-1;
		else
			tot-=ans;
		sel[i]=1-sel[i];
		printf("%d\n",tot );
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
int arr[200005],sel[200005],val[500005];
vector<int>v[500005];
int power[10];
int main()
{
	int i,j,k,n,q;
	sd(n);
	sd(q);
	for(i=1;i<=n;i++)
		sd(arr[i]);
	power[0]=1;
	for(i=1;i<10;i++)
		power[i]=2*power[i-1];
	for(i=2;i<=500000;i++)
	{
		if(v[i].empty())
		{
			for(j=i;j<=500000;j+=i)
			{
				v[j].pb(i);
			}
		}
	}
	int tot=0;
	while(q--)
	{
		sd(i);
		j=arr[i];
		k=power[v[arr[i]].size()];
		int ans=0;
		for(j=0;j<k;j++)
		{
			int temp=1,temp2=j,x=0,y=0;
			while(temp2!=0)
			{
				if(temp2%2==1)
				{
					temp*=v[arr[i]][x];
					y++;
				}
				x++;
				temp2/=2;
			}
			if(y%2==0)
			{
				ans+=val[temp];
			}
			else
				ans-=val[temp];
			if(sel[i]==0)
				val[temp]++;
			else
				val[temp]--;
		}
		if(sel[i]==0)
			tot+=ans;
		else
			tot-=ans-1;
		sel[i]=1-sel[i];
		printf("%d\n",tot );
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
int arr[200005],sel[200005],val[500005];
vector<int>v[500005];
int power[10];
int main()
{
	int i,j,k,n,q;
	sd(n);
	sd(q);
	for(i=1;i<=n;i++)
		sd(arr[i]);
	power[0]=1;
	for(i=1;i<10;i++)
		power[i]=2*power[i-1];
	for(i=2;i<=500000;i++)
	{
		if(v[i].empty())
		{
			for(j=i;j<=500000;j+=i)
			{
				v[j].pb(i);
			}
		}
	}
	int tot=0;
	while(q--)
	{
		sd(i);
		//j=arr[i];
		k=power[v[arr[i]].size()];
		if(sel[i]==1)
		{
			for(j=0;j<k;j++)
			{
				int temp=1,temp2=j,x=0;
				while(temp2!=0)
				{
					if(temp2%2==1)
					{
						temp*=v[arr[i]][x];
					}
					temp2/=2;
					x++;
				}
				val[temp]--;
			}
		}
		int ans=0;
		for(j=0;j<k;j++)
		{
			int temp=1,temp2=j,x=0,y=0;
			while(temp2!=0)
			{
				if(temp2%2==1)
				{
					temp*=v[arr[i]][x];
					y++;
				}
				x++;
				temp2/=2;
			}
			if(y%2==0)
			{
				ans+=val[temp];
			}
			else
				ans-=val[temp];
			if(sel[i]==0)
				val[temp]++;
			//cout<<j<<" "<<temp<<" "<<endl;
		}
		if(sel[i]==0){
			tot+=ans;
		}
		else
			tot-=ans;
		sel[i]=1-sel[i];
		printf("%d\n",tot );
	}
	return 0;
}


#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 5e5 + 7;
const int M = N * 3;
const int inf = 1e9 + 7;
const int base = 1e9 + 9;
const double pi = acos(-1);
const double ep = 1e-9;

int d[N];
int a[N];
set<int> st;
bool kt[N];
int n, q;
vi prime;
//map<int, int> pos;
int L[N];

void init(){
    rep(i, 2, N){
        if (kt[i]) continue;
        prime.pb(i);
        //pos[i] = prime.size();
        int j = 2;
        while ((ll)i * j < N){
            kt[i * j ++] = 1;
        }
    }
}

int main(){
    //freopen("in.txt", "r", stdin);
    init();
    cin >> n >> q;
    rep(i, 0, n)
        scanf("%d", &a[i+1]);
    ll ans = 0;
    rep(tt, 0, q){
        int u;
        scanf("%d", &u);
        int p[6], m = 0, x = a[u];
        if (a[u] == 1){
            if (st.count(u)) {
                ans -= st.size() - 1;
            }
            else {
                ans += st.size();
                st.insert(u);
                //ans += L[u];
            }
            printf("%I64d\n", ans);
            continue;
        }

        for(int j = 0, mmm = sqrt(u) + 1; prime[j] <= mmm; j++){
            if (x % prime[j] == 0){
                p[m++] = prime[j];
                while (x % prime[j] == 0)
                    x/= prime[j];
            }
        }
        if (x > 1) p[m++] = x;

        int cnt = 0;
        vi tmp;
        rep(mask, 1, 1 << m){
            int bitcnt = __builtin_popcount(mask);
            int prod = 1;
            rep(i, 0, mask)
                if (mask & (1 << i)){
                    prod *= p[i];
                }
            if (bitcnt & 1) cnt += d[prod];
            else cnt -= d[prod];
            tmp.pb(prod);
        }
        //if (u == 5) cout<<tmp.size()<<endl;
        cnt = st.size() - cnt;
        //cout<<u<<" "<<cnt<<endl;

        if (st.count(u)){

            ans -= cnt;
            rep(i, 0, tmp.size())
                d[tmp[i]]--;
        }else{
            ans += cnt;
            rep(i, 0, tmp.size())
                d[tmp[i]] ++;
            st.insert(u);
        }
        printf("%I64d\n", ans);
    }

}


#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 5e5 + 7;
const int M = N * 3;
const int inf = 1e9 + 7;
const int base = 1e9 + 9;
const double pi = acos(-1);
const double ep = 1e-9;

ll d[N];
int a[N];
bool kt[N];
int n, q;
vi prime;
vi tmp;
int sl = 0;
int p[N];

void init(){
    rep(i, 2, N){
        if (kt[i]) continue;
        prime.pb(i);
        //pos[i] = prime.size();
        int j = 2;
        while ((ll)i * j < N){
            kt[i * j ++] = 1;
        }
    }
}

int main(){
    //freopen("in.txt", "r", stdin);
    init();
    //cout<<prime.size()<<endl;;
    cin >> n >> q;
    rep(i, 0, n){
        scanf("%d", &a[i+1]);
    }
    memset(kt,0, sizeof(kt));
    //return 0;
    ll ans = 0;
    rep(tt, 0, q){
        int u;
        //u = rand() % n + 1;
        scanf("%d", &u);
        //cout<<a[u]<<":";
        //continue;
        int m = 0, x = a[u];
        if (a[u] == 1){
            if (kt[u]) {
                ans -= sl - 1;
                //st.erase(u);
                kt[u] = 0;sl--;
            }
            else {
                ans += sl;
                //st.insert(u);
                kt[u] = 1;sl++;
                //ans += L[u];
            }
            printf("%I64d\n", ans);
            continue;
        }

        //break;

        for(int j = 0, mmm = sqrt(u); prime[j] <= mmm; j++){
            if (x % prime[j] == 0){
                p[m++] = prime[j];
                while (x % prime[j] == 0)
                    x/= prime[j];
            }
        }
        if (x > 1) p[m++] = x;
        //continue;
        int cnt = 0;
        tmp.clear();
        rep(mask, 1, 1 << m){
            int bitcnt = __builtin_popcount(mask);
            int prod = 1;
            rep(i, 0, mask)
                if (mask & (1 << i)){
                    prod *= p[i];
                }
            if (bitcnt & 1) cnt += d[prod];
            else cnt -= d[prod];
            if (prod >= N) {
                cout<<"fuck";

            }
            tmp.pb(prod);

        }
        //continue;
        //if (u == 5) cout<<tmp.size()<<endl;
        cnt = sl - cnt;
        //cout<<u<<" "<<cnt<<endl;

        if (kt[u]){

            ans -= cnt;
            //st.erase(u);
            kt[u] = 0; sl--;
            rep(i, 0, tmp.size())
                d[tmp[i]]--;
        }else{
            ans += cnt;
            rep(i, 0, tmp.size())
                d[tmp[i]] ++;
            //st.insert(u);
            sl++;
            kt[u] = 1;
        }
        printf("%I64d\n", ans);
    }
}


#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 5e5 + 7;
const int M = N * 3;
const int inf = 1e9 + 7;
const int base = 1e9 + 9;
const double pi = acos(-1);
const double ep = 1e-9;

int d[N];
int a[N];
int kt[N];
int n, q;
vi prime;
vi tmp;
int sl = 0;
int p[N];

void init(){
    rep(i, 2, N){
        if (kt[i]) continue;
        prime.pb(i);
        //pos[i] = prime.size();
        int j = 2;
        while ((ll)i * j < N){
            kt[i * j] = 1;
            j++;
        }
    }
}

int main(){
    //freopen("in.txt", "r", stdin);
    init();
    //cout<<prime.size()<<endl;;
    cin >> n >> q;
    rep(i, 0, n){
        scanf("%d", &a[i+1]);
    }
    memset(kt, 0, sizeof(kt));
    //return 0;
    ll ans = 0;
    rep(tt, 0, q){
        int u;
        //u = rand() % n + 1;
        scanf("%d", &u);
        //cout<<a[u]<<":";
        //continue;
        int m = 0, x = a[u];
        if (a[u] == 1){
            if (kt[u]) {
                ans -= sl - 1;
                //st.erase(u);
                kt[u] = 0;
                sl--;
            }
            else {
                ans += sl;
                //st.insert(u);
                kt[u] = 1;sl++;
                //ans += L[u];
            }
            printf("%I64d\n", ans);
            continue;
        }

        //break;

        for(int j = 0, mmm = sqrt(u) + 1; prime[j] <= mmm; j++){
            if (x % prime[j] == 0){
                p[m++] = prime[j];
                while (x % prime[j] == 0)
                    x/= prime[j];
            }
        }
        if (x > 1) p[m++] = x;
        //continue;
        ll cnt = 0;
        tmp.clear();
        rep(mask, 1, 1 << m){
            int bitcnt = __builtin_popcount(mask);
            int prod = 1;
            rep(i, 0, mask)
                if (mask & (1 << i)){
                    prod *= p[i];
                }
            if (bitcnt & 1) cnt += d[prod];
            else cnt -= d[prod];
            if (prod >= N) {
                cout<<"fuck";

            }
            tmp.pb(prod);
        }
        //continue;
        //if (u == 5) cout<<tmp.size()<<endl;
        cnt = sl - cnt;
        //cout<<u<<" "<<cnt<<endl;

        if (kt[u]){
            ans -= cnt;
            kt[u] = 0; sl--;
            rep(i, 0, tmp.size())
                d[tmp[i]] --;
        }else{
            ans += cnt;
            rep(i, 0, tmp.size())
                d[tmp[i]] ++;
            sl++;
            kt[u] = 1;
        }
        printf("%I64d\n", ans);
    }
}


#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 5e5 + 7;
const int M = N * 3;
const int inf = 1e9 + 7;
const int base = 1e9 + 9;
const double pi = acos(-1);
const double ep = 1e-9;

int d[N];
int a[N];
int kt[N];
int n, q;
vi prime;
vi tmp;
int sl = 0;
int p[N];

void init(){
    rep(i, 2, N){
        if (kt[i]) continue;
        prime.pb(i);
        //pos[i] = prime.size();
        int j = 2;
        while ((ll)i * j < N){
            kt[i * j] = 1;
            j++;
        }
    }
}

int main(){
    //freopen("in.txt", "r", stdin);
    init();
    memset(kt, 0, sizeof(kt));
    cin >> n >> q;
    rep(i, 0, n){
        scanf("%d", &a[i + 1]);
    }

    ll ans = 0;

    rep(i, 0, q){
        int u;
        scanf("%d", &u);

        if (a[u] == 1){
            if (kt[u] == 1){
                kt[u] = 0;
                ans -= sl - 1;
                sl--;
            }else{
                kt[u] = 1;
                ans += sl;
                sl ++;
            }
            printf("%I64d\n", ans);
            continue;
        }
        int m = 0;
        int x = a[u];
        for(int j = 0; prime[j] * prime[j] <= a[u]; j++){
            if (x % prime[j] == 0){
                p[m++] = prime[j];
                while (x % prime[j] == 0) x /= prime[j];
            }
        }
        if (x > 1) p[m++] = x;
        tmp.clear();
        ll cnt = 0;
        rep(mask, 1, 1 << m){
            int odd = __builtin_popcount(mask);
            int pr = 1;
            rep(j, 0, m)
                if (mask & (1 << j)) pr *= p[j];
            tmp.pb(pr);
            if (odd & 1) cnt += d[pr];
            else cnt -= d[pr];
        }
        cnt = sl - cnt;

        if (kt[u] == 1){
            kt[u] = 0;
            sl--;
            ans -= cnt;
            rep(i, 0, tmp.size())
                d[tmp[i]]--;
        }else{
            kt[u] = 1;
            sl++;
            ans += cnt;
            rep(i, 0, tmp.size())
                d[tmp[i]]++;
        }
        printf("%I64d\n", ans);
    }
}


#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 5e5 + 7;
const int M = N * 3;
const int inf = 1e9 + 7;
const int base = 1e9 + 9;
const double pi = acos(-1);
const double ep = 1e-9;

ll d[N];
int a[N];
bool kt[N];
int n, q;
vi prime;
vi tmp;
int sl = 0;
int p[N];

void init(){
    rep(i, 2, N){
        if (kt[i]) continue;
        prime.pb(i);
        //pos[i] = prime.size();
        int j = 2;
        while ((ll)i * j < N){
            kt[i * j ++] = 1;
        }
    }
}

int main(){
    //freopen("in.txt", "r", stdin);
    init();
    //cout<<prime.size()<<endl;;
    cin >> n >> q;
    rep(i, 0, n){
        scanf("%d", &a[i+1]);
    }
    memset(kt,0, sizeof(kt));
    //return 0;
    ll ans = 0;
    rep(tt, 0, q){
        int u;
        //u = rand() % n + 1;
        scanf("%d", &u);
        //cout<<a[u]<<":";
        //continue;
        int m = 0, x = a[u];
        if (a[u] == 1){
            if (kt[u]) {
                ans -= sl - 1;
                //st.erase(u);
                kt[u] = 0;
                sl--;
            }
            else {
                ans += sl;
                //st.insert(u);
                kt[u] = 1;sl++;
                //ans += L[u];
            }
            printf("%I64d\n", ans);
            continue;
        }

        //break;

        for(int j = 0, mmm = sqrt(u) + 1; prime[j] <= mmm; j++){
            if (x % prime[j] == 0){
                p[m++] = prime[j];
                while (x % prime[j] == 0)
                    x/= prime[j];
            }
        }
        if (x > 1) p[m++] = x;
        //continue;
        ll cnt = 0;
        tmp.clear();
        rep(mask, 1, 1 << m){
            int bitcnt = __builtin_popcount(mask);
            int prod = 1;
            rep(i, 0, mask)
                if (mask & (1 << i)){
                    prod *= p[i];
                }
            if (bitcnt & 1) cnt += d[prod];
            else cnt -= d[prod];
            if (prod >= N) {
                cout<<"fuck";

            }
            tmp.pb(prod);

        }
        //continue;
        //if (u == 5) cout<<tmp.size()<<endl;
        cnt = sl - cnt;
        //cout<<u<<" "<<cnt<<endl;

        if (kt[u]){

            ans -= cnt;
            //st.erase(u);
            kt[u] = 0; sl--;
            rep(i, 0, tmp.size())
                d[tmp[i]]--;
        }else{
            ans += cnt;
            rep(i, 0, tmp.size())
                d[tmp[i]] ++;
            //st.insert(u);
            sl++;
            kt[u] = 1;
        }
        printf("%I64d\n", ans);
    }
}


#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 5e5 + 7;
const int M = N * 3;
const int inf = 1e9 + 7;
const int base = 1e9 + 9;
const double pi = acos(-1);
const double ep = 1e-9;

ll d[N];
int a[N];
set<int> st;
bool kt[N];
int n, q;
vi prime;

void init(){
    rep(i, 2, N){
        if (kt[i]) continue;
        prime.pb(i);
        //pos[i] = prime.size();
        int j = 2;
        while ((ll)i * j < N){
            kt[i * j ++] = 1;
        }
    }
}

int main(){
    //freopen("in.txt", "r", stdin);
    init();
    //cout<<prime.size()<<endl;;
    cin >> n >> q;
    rep(i, 0, n)
        scanf("%d", &a[i+1]);
    ll ans = 0;
    rep(tt, 0, q){
        int u;
        scanf("%d", &u);
        //cout<<a[u]<<":";
        //continue;
        int p[8], m = 0, x = a[u];
        if (a[u] == 1){
            if (st.count(u)) {
                ans -= st.size() - 1;
                st.erase(u);
            }
            else {
                ans += st.size();
                st.insert(u);
                //ans += L[u];
            }
            printf("%I64d\n", ans);
            continue;
        }

        //break;

        for(int j = 0, mmm = sqrt(u) + 1; prime[j] <= mmm; j++){
            if (x % prime[j] == 0){
                p[m++] = prime[j];
                while (x % prime[j] == 0)
                    x/= prime[j];
            }
        }
        if (x > 1) p[m++] = x;

        int cnt = 0;
        vi tmp;
        rep(mask, 1, 1 << m){
            int bitcnt = __builtin_popcount(mask);
            int prod = 1;
            rep(i, 0, mask)
                if (mask & (1 << i)){
                    prod *= p[i];
                }
            if (bitcnt & 1) cnt += d[prod];
            else cnt -= d[prod];
            tmp.pb(prod);
        }
        //if (u == 5) cout<<tmp.size()<<endl;
        cnt = st.size() - cnt;
        //cout<<u<<" "<<cnt<<endl;

        if (st.count(u)){

            ans -= cnt;
            st.erase(u);
            rep(i, 0, tmp.size())
                d[tmp[i]]--;
        }else{
            ans += cnt;
            rep(i, 0, tmp.size())
                d[tmp[i]] ++;
            st.insert(u);
        }
        printf("%I64d\n", ans);
    }

}


#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 5e5 + 7;
const int M = N * 3;
const int inf = 1e9 + 7;
const int base = 1e9 + 9;
const double pi = acos(-1);
const double ep = 1e-9;

int d[N];
int a[N];
int kt[N];
int n, q;
vi prime;
vi tmp;
int sl = 0;
int p[N];

void init(){
    rep(i, 2, N){
        if (kt[i]) continue;
        prime.pb(i);
        //pos[i] = prime.size();
        int j = 2;
        while ((ll)i * j < N){
            kt[i * j] = 1;
            j++;
        }
    }
}

int main(){
    //freopen("in.txt", "r", stdin);
    init();
    //cout<<prime.size()<<endl;;
    cin >> n >> q;
    rep(i, 0, n){
        scanf("%d", &a[i+1]);
    }
    memset(kt, 0, sizeof(kt));
    //return 0;
    ll ans = 0;
    rep(tt, 0, q){
        int u;
        //u = rand() % n + 1;
        scanf("%d", &u);
        //cout<<a[u]<<":";
        //continue;
        int m = 0, x = a[u];
        if (a[u] == 1){
            if (kt[u]) {
                ans -= sl - 1;
                //st.erase(u);
                kt[u] = 0;
                sl--;
            }
            else {
                ans += sl;
                //st.insert(u);
                kt[u] = 1;sl++;
                //ans += L[u];
            }
            printf("%I64d\n", ans);
            continue;
        }

        //break;

        for(int j = 0, mmm = sqrt(a[u]) + 1; prime[j] <= mmm; j++){
            if (x % prime[j] == 0){
                p[m++] = prime[j];
                while (x % prime[j] == 0)
                    x/= prime[j];
            }
        }
        if (x > 1) p[m++] = x;
        //continue;
        ll cnt = 0;
        tmp.clear();
        rep(mask, 1, 1 << m){
            int bitcnt = __builtin_popcount(mask);
            int prod = 1;
            rep(i, 0, mask)
                if (mask & (1 << i)){
                    prod *= p[i];
                }
            if (bitcnt & 1) cnt += d[prod];
            else cnt -= d[prod];
            if (prod >= N) {
                cout<<"fuck";

            }
            tmp.pb(prod);
        }
        //continue;
        //if (u == 5) cout<<tmp.size()<<endl;
        cnt = sl - cnt;
        //cout<<u<<" "<<cnt<<endl;

        if (kt[u]){
            ans -= cnt;
            kt[u] = 0; sl--;
            rep(i, 0, tmp.size())
                d[tmp[i]] --;
        }else{
            ans += cnt;
            rep(i, 0, tmp.size())
                d[tmp[i]] ++;
            sl++;
            kt[u] = 1;
        }
        printf("%I64d\n", ans);
    }
}


#include <bits/stdc++.h>

#define NN 500500

using namespace std;

typedef long long INT;

typedef pair <int, int> pii;

int fl[NN], p[NN], pk, mk[NN];

void pre(){

	for(int i=2; i<NN; i++){

		if(fl[i]) continue;

		mk[i]=i;

		p[pk++]=i;

		if(i>1000) continue;

		for(int j=i*i; j<NN; j+=i){

			fl[j]=1;

			if(!mk[j]) mk[j]=i;

		}

	}

}

int a[NN];

vector <int> adj[NN];

int cnt[NN], vst[NN];

int main (){

	pre();

	int n, m;

	cin >> n >> m;

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

		scanf("%d", a+i);

		int b=a[i];

		a[i]=1;

		while(b>1){

			int c=mk[b];

			a[i]*=c;

			adj[i].push_back(c);

			while(b%c==0) b/=c;

		}

	}

	int u;

	INT ans=0, tot=0;

	while(m--){

		scanf("%d", &u);

		if(!vst[u]){

			vst[u]=1;

			ans+=tot++;

			for(int sz=1<<adj[u].size(), i=1; i<sz; i++){

				int m=1, b=i;

				while(b){

					int c=__builtin_ctz(b);

					b-=1<<c;

					m*=adj[u][c];

				}

				if(__builtin_popcount(i)&1) ans-=cnt[m];

				else ans+=cnt[m];

				cnt[m]++;

			}

		}

		else {

			vst[u]=0;

			ans-=--tot;

			for(int sz=1<<adj[u].size(), i=1; i<sz; i++){

				int m=1, b=i;

				while(b){

					int c=__builtin_ctz(b);

					b-=1<<c;

					m*=adj[u][c];

				}

				if(__builtin_popcount(i)&1) ans+=cnt[m];

				else ans-=cnt[m];

				cnt[m]--;

			}

		}

		printf("%I64d\n", ans);

	}

	return 0;

}


#include <bits/stdc++.h>

#define NN 500500

using namespace std;

typedef long long INT;

typedef pair <int, int> pii;

int fl[NN], p[NN], pk, mk[NN];

void pre(){

	for(int i=2; i<NN; i++){

		if(fl[i]) continue;

		mk[i]=i;

		p[pk++]=i;

		if(i>1000) continue;

		for(int j=i*i; j<NN; j+=i){

			fl[j]=1;

			if(!mk[j]) mk[j]=i;

		}

	}

}

int a[NN];

vector <int> adj[NN];

int cnt[NN], vst[NN];

int main (){

	pre();

	int n, m;

	cin >> n >> m;

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

		scanf("%d", a+i);

		int b=a[i];

		a[i]=1;

		while(b>1){

			int c=mk[b];

			a[i]*=c;

			adj[i].push_back(c);

			while(b%c==0) b/=c;

		}

	}

	int u;

	INT ans=0, tot=0;

	while(m--){

		scanf("%d", &u);

		if(!vst[u]){

			vst[u]=1;

			ans+=tot++;

			for(int sz=1<<adj[u].size(), i=1; i<sz; i++){

				int m=1, b=i;

				while(b){

					int c=__builtin_ctz(b);

					b-=1<<c;

					m*=adj[u][c];

				}

				if(__builtin_popcount(i)&1) ans-=cnt[m];

				else ans+=cnt[m];

				cnt[m]++;

			}

		}

		else {

			vst[u]=0;

			ans-=--tot;

			for(int sz=1<<adj[u].size(), i=1; i<sz; i++){

				int m=1, b=i;

				while(b){

					int c=__builtin_ctz(b);

					b-=1<<c;

					m*=adj[u][c];

				}

				cnt[m]--;

				if(__builtin_popcount(i)&1) ans+=cnt[m];

				else ans-=cnt[m];

			}

		}

		printf("%I64d\n", ans);

	}

	return 0;

}


#include<bits/stdc++.h>

#define NN 211111

using namespace std;

typedef long long INT;

int a[NN], vst[511111];

INT cnt[511111];

vector<int> dv[NN];

int main(){

	int n,q,i,j;

	cin>>n>>q;

	for(i=1; i<=n; i++){

		scanf("%d", a+i);

		int u=a[i];

		for(j=2; j*j<=u; j++){

			if(u%j) continue;

			dv[i].push_back(j);

			while(u%j==0) u/=j;

		}

		if(u>1) dv[i].push_back(u);

	}

	INT ans=0, tot=0;

	while(q--){

		int u;

		scanf("%d", &u);

		if(!vst[u]){

			vst[u]=1;

			ans+=tot++;

			int sz=dv[u].size();

			for(i=1; i<(1<<sz); i++){

				int tmp=1;

				for(j=0; j<sz; j++){

					if(i&(1<<j)) tmp*=dv[u][j];

				}

				if(__builtin_popcount(i)&1) ans-=cnt[tmp]++;

				else ans+=cnt[tmp]++;

			}

		}

		else {

			vst[u]=0;

			ans-=--tot;

			int sz=dv[u].size();

			for(i=1; i<(1<<sz); i++){

				int tmp=1;

				for(j=0; j<sz; j++){

					if(i&(1<<j)) tmp*=dv[u][j];

				}

				if(__builtin_popcount(i)&1) ans+=--cnt[tmp];

				else ans-=--cnt[tmp];

			}

		}

		cout<<ans<<endl;

	}

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-9

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 202020

int val[NN], prime[NN], flag[NN], np;

VI fac[NN];

int cnt[NN], vst[NN], a[NN], val1[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	val1[1]=val[1]=1; fac[1].pb(1);

	for (int i=2; i<NN; i++) {

		if (!flag[i]) prime[np++]=i, flag[i]=i;

		for (int j=0; j<np && prime[j]*i<NN; j++) {

			flag[prime[j]*i]=prime[j];

			if (prime[j]==flag[i]) break;

		}

		int v=i/flag[i];

		val1[i]=val1[v];

		if (flag[v]!=flag[i]) val[i]=-val[v], val1[i]*=flag[i];

		if (val[i]) {

			for (int j=0; j<fac[v].size(); j++) fac[i].pb(fac[v][j]), fac[i].pb(fac[v][j]*flag[i]);

		}

	}

	int n, q;

	gn(n, q);

	for (int i=1; i<=n; i++) gn(a[i]);

	INT ans=0;

	while (q--) {

		int u;

		gn(u);

		int v=val1[a[u]];

		if (vst[u]) {

			for (int i=0; i<fac[v].size(); i++) {

				int t=fac[v][i];

				cnt[t]--;

			}

			int mid=0;

			for (int i=0; i<fac[v].size(); i++) {

				int t=fac[v][i];

				mid+=cnt[t]*val[t];

			}

			ans-=mid;

		} else {

			int mid=0;

			for (int i=0; i<fac[v].size(); i++) {

				int t=fac[v][i];

				mid+=cnt[t]*val[t];

			}

			ans+=mid;

			for (int i=0; i<fac[v].size(); i++) {

				int t=fac[v][i];

				cnt[t]++;

			}

		}

		vst[u]^=1;

		println(ans);

	}

	return 0;

}


#include<bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define eps 1e-8

#define x first

#define y second

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) ((x) ? (__builtin_clzll(x)) : 0)

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define shit(a) (1 << (a))

#define rev(a) (power(a, mod-2, mod))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> ppi;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

int power(int a, int b, int m, int ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 200111

#define MM 500111

int flag[MM];

int fir[MM];

void pre() {

	for(int i=2; i<MM; i++) if(flag[i] == 0){

		for(int j=i; j<MM; j+=i) {

			flag[j] = 1;

			if(fir[j] == 0) fir[j] = i;

		}

	}

}

int a[NN];

int now=0;

INT ans=0;

vector<int> p;

vector<pii> dv[NN];

int cnt[MM];

void insert(int u) {

	for(int i=0; i<sz(dv[u]); i++) {

		int uu=dv[u][i].x, sg=dv[u][i].y;

		ans += sg * cnt[uu];

		cnt[uu]++;

	}

}

void erase(int u) {

	for(int i=0; i<sz(dv[u]); i++) {

		int uu=dv[u][i].x, sg=dv[u][i].y;

		cnt[uu]--;

		ans -= sg * cnt[uu];

	}

}

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n, q;

	cin >> n >> q;

	pre();

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

		gn(a[i]);

		int u=a[i];

		p.clear();

		while(u>1) {

			int v=fir[u];

			while(u%v==0) u/=v;

			p.pb(v);

		}

		int m=sz(p);

		for(int ii=0; ii<1<<m; ii++) {

			int tmp=1;

			for(int j=0; j<m; j++) if(bit(ii, j)) {

				tmp *= p[j];

			}

			dv[i].pb(pii(tmp, (bpt(ii) & 1) ? -1 : 1));

		}

	}

	memset(flag, 0, sizeof flag);

	while(q--) {

		int u; gn(u);

		if(flag[u]==0) insert(u), now++, flag[u]=1;

		else erase(u), now--, flag[u] = 0;

		println(ans);

	}

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-9

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 502020

int val[NN], prime[NN], flag[NN], np;

VI fac[NN];

int cnt[NN], vst[NN], a[NN], val1[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	val1[1]=val[1]=1; fac[1].pb(1);

	for (int i=2; i<NN; i++) {

		if (!flag[i]) prime[np++]=i, flag[i]=i;

		for (int j=0; j<np && prime[j]*i<NN; j++) {

			flag[prime[j]*i]=prime[j];

			if (prime[j]==flag[i]) break;

		}

		int v=i/flag[i];

		val1[i]=val1[v];

		if (flag[v]!=flag[i]) val[i]=-val[v], val1[i]*=flag[i];

		if (val[i]) {

			for (int j=0; j<fac[v].size(); j++) fac[i].pb(fac[v][j]), fac[i].pb(fac[v][j]*flag[i]);

		}

	}

	int n, q;

	gn(n, q);

	for (int i=1; i<=n; i++) gn(a[i]);

	INT ans=0;

	while (q--) {

		int u;

		gn(u);

		int v=val1[a[u]];

		if (vst[u]) {

			for (int i=0; i<fac[v].size(); i++) {

				int t=fac[v][i];

				cnt[t]--;

			}

			int mid=0;

			for (int i=0; i<fac[v].size(); i++) {

				int t=fac[v][i];

				mid+=cnt[t]*val[t];

			}

			ans-=mid;

		} else {

			int mid=0;

			for (int i=0; i<fac[v].size(); i++) {

				int t=fac[v][i];

				mid+=cnt[t]*val[t];

			}

			ans+=mid;

			for (int i=0; i<fac[v].size(); i++) {

				int t=fac[v][i];

				cnt[t]++;

			}

		}

		vst[u]^=1;

		println(ans);

	}

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 500500

int vst[NN];

void pre(){

	for(int i=2; i<NN; i++){

		if(vst[i]) continue;

		vst[i]=i;

		if(i>1000) continue;

		for(int j=i*i; j<NN; j+=i) if(!vst[j]) vst[j]=i;

	}

}

int flag[NN];

int cnt[NN];

VI vec[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	pre();

	int n, m;

	gn(n, m);

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

		int u;

		gn(u);

		while(u>1){

			int d=vst[u];

			vec[i].pb(d);

			while(u%d==0) u/=d;

		}

	}

	INT ans=0;

	while(m--){

		int u;

		gn(u);

		if(flag[u]){

			int sz=vec[u].size();

			int tot=0;

			for(int i=0; i<1<<sz; i++){

				int mul=1;

				for(int j=0; j<sz; j++) if(bit(i, j)) mul*=vec[u][j];

				cnt[mul]--;

				if(bpt(i)&1) tot-=cnt[mul];

				else tot+=cnt[mul];

			}

			flag[u]=0;

			ans-=tot;

		}

		else {

			int sz=vec[u].size();

			int tot=0;

			for(int i=0; i<1<<sz; i++){

				int mul=1;

				for(int j=0; j<sz; j++) if(bit(i, j)) mul*=vec[u][j];

				if(bpt(i)&1) tot-=cnt[mul];

				else tot+=cnt[mul];

				cnt[mul]++;

			}

			flag[u]=1;

			ans+=tot;

		}

		println(ans);

	}

	return 0;

}


#include <cstdio>
#include <cstdlib>
using namespace std;
const int maxn=200005;
const int maxh=500005;
const int maxe=7000005;
int N,Q,H,h[maxn];
int E,di[maxe],dnext[maxe],dlast[maxh];
int tot_prime,prime[maxh],mu[maxh];
bool pF[maxh];
long long ans;
int sc[maxh],c[maxh];
bool F[maxn];
inline void _getnum(int &xx)
{
    char tt=getchar();
    while(tt<'0'||tt>'9')tt=getchar();
    for(xx=0;tt>='0'&&tt<='9';tt=getchar())xx=xx*10+(tt-'0');
}
int main()
{
    //freopen("datax.in","r",stdin);
    //freopen("my-1.out","w",stdout);
    int i,j,k,t,d;
    _getnum(N);_getnum(Q);
    for(i=1;i<=N;i++)
    {
        _getnum(h[i]);
        if(H<h[i])H=h[i];
    }
    for(i=1;i<=H;i++)
        for(j=i;j<=H;j+=i)
        {
            di[++E]=i;
            dnext[E]=dlast[j];
            dlast[j]=E;
        }
    mu[1]=1;
    for(i=2;i<=H;i++)
        pF[i]=true;
    for(i=2;i<=H;i++)
    {
        if(pF[i]==true)
        {
            prime[++tot_prime]=i;
            mu[i]=-1;
        }
        for(j=1;j<=tot_prime&&(k=i*prime[j])<=H;j++)
        {
            pF[k]=false;
            if(i%prime[j]!=0)
                mu[k]=-mu[i];
            else
            {
                mu[k]=0;
                break;
            }
        }
    }
    for(i=1;i<=Q;i++)
    {
        _getnum(k);
        t=F[k]?-1:1;
        F[k]^=1;
        k=h[k];
        c[k]+=t;
        for(j=dlast[k];j>0;j=dnext[j])
        {
            d=di[j];
            ans-=mu[d]*1ll*sc[d]*sc[d];
            sc[d]+=t;
            ans+=mu[d]*1ll*sc[d]*sc[d];
        }
        printf("%I64d\n",(ans-c[1])>>1);
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
using namespace std;
const int maxn=200005;
const int maxh=500005;
const int maxe=5000005;
int N,Q,H,h[maxn];
int E,di[maxe],dnext[maxe],dlast[maxh];
int tot_prime,prime[maxh];
char mu[maxh];
bool pF[maxh];
long long ans;
int sc[maxh],c[maxh];
bool F[maxn];
inline void _getnum(int &xx)
{
    char tt=getchar();
    while(tt<'0'||tt>'9')tt=getchar();
    for(xx=0;tt>='0'&&tt<='9';tt=getchar())xx=xx*10+(tt-'0');
}
int main()
{
    //freopen("datax.in","r",stdin);
    //freopen("my-2.out","w",stdout);
    int i,j,k,t,d;
    _getnum(N);_getnum(Q);
    for(i=1;i<=N;i++)
    {
        _getnum(h[i]);
        if(H<h[i])H=h[i];
    }
    mu[1]=1;
    for(i=2;i<=H;i++)
        pF[i]=true;
    for(i=2;i<=H;i++)
    {
        if(pF[i]==true)
        {
            prime[++tot_prime]=i;
            mu[i]=-1;
        }
        for(j=1;j<=tot_prime&&(k=i*prime[j])<=H;j++)
        {
            pF[k]=false;
            if(i%prime[j]!=0)
                mu[k]=-mu[i];
            else
            {
                mu[k]=0;
                break;
            }
        }
    }
    for(i=1;i<=H;i++)
    {
        if(mu[i]==0)
            continue;
        for(j=i;j<=H;j+=i)
        {
            di[++E]=i;
            dnext[E]=dlast[j];
            dlast[j]=E;
        }
    }
    for(i=1;i<=Q;i++)
    {
        _getnum(k);F[k]^=1;
        if(F[k]==true)
        {
            k=h[k];c[k]++;
            for(j=dlast[k];j>0;j=dnext[j])
            {
                d=di[j];
                if(mu[d]==1)ans+=(sc[d]<<1)+1;
                else ans-=(sc[d]<<1)+1;
                sc[d]++;
            }
        }
        else
        {
            k=h[k];c[k]--;
            for(j=dlast[k];j>0;j=dnext[j])
            {
                d=di[j];
                sc[d]--;
                if(mu[d]==1)ans-=(sc[d]<<1)+1;
                else ans+=(sc[d]<<1)+1;
            }
        }
        printf("%I64d\n",(ans-c[1])>>1);
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
using namespace std;
const int maxn=20005;
const int maxh=500005;
const int maxe=7000005;
int N,Q,H,h[maxn];
int E,di[maxe],dnext[maxe],dlast[maxh];
int tot_prime,prime[maxh],mu[maxh];
bool pF[maxh];
long long ans;
int sc[maxn],c[maxn];
bool F[maxn];
inline void _getnum(int &xx)
{
    char tt=getchar();
    while(tt<'0'||tt>'9')tt=getchar();
    for(xx=0;tt>='0'&&tt<='9';tt=getchar())xx=xx*10+(tt-'0');
}
int main()
{
    //freopen("datax.in","r",stdin);
    //freopen("my-1.out","w",stdout);
    int i,j,k,t,d;
    _getnum(N);_getnum(Q);
    for(i=1;i<=N;i++)
    {
        _getnum(h[i]);
        if(H<h[i])H=h[i];
    }
    for(i=1;i<=H;i++)
        for(j=i;j<=H;j+=i)
        {
            di[++E]=i;
            dnext[E]=dlast[j];
            dlast[j]=E;
        }
    mu[1]=1;
    for(i=2;i<=H;i++)
        pF[i]=true;
    for(i=2;i<=H;i++)
    {
        if(pF[i]==true)
        {
            prime[++tot_prime]=i;
            mu[i]=-1;
        }
        for(j=1;j<=tot_prime&&(k=i*prime[j])<=H;j++)
        {
            pF[k]=false;
            if(i%prime[j]!=0)
                mu[k]=-mu[i];
            else
            {
                mu[k]=0;
                break;
            }
        }
    }
    for(i=1;i<=Q;i++)
    {
        _getnum(k);
        t=F[k]?-1:1;
        F[k]^=1;
        k=h[k];
        c[k]+=t;
        for(j=dlast[k];j>0;j=dnext[j])
        {
            d=di[j];
            ans-=mu[d]*1ll*sc[d]*sc[d];
            sc[d]+=t;
            ans+=mu[d]*1ll*sc[d]*sc[d];
        }
        printf("%I64d\n",(ans-1ll*c[1]*c[1])>>1);
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
using namespace std;
const int maxn=20005;
const int maxh=500005;
const int maxe=7000005;
int N,Q,H,h[maxn];
int E,di[maxe],dnext[maxe],dlast[maxh];
int tot_prime,prime[maxh],mu[maxh];
bool pF[maxh];
long long ans;
int sc[maxh],c[maxh];
bool F[maxn];
inline void _getnum(int &xx)
{
    char tt=getchar();
    while(tt<'0'||tt>'9')tt=getchar();
    for(xx=0;tt>='0'&&tt<='9';tt=getchar())xx=xx*10+(tt-'0');
}
int main()
{
    //freopen("datax.in","r",stdin);
    //freopen("my-1.out","w",stdout);
    int i,j,k,t,d;
    _getnum(N);_getnum(Q);
    for(i=1;i<=N;i++)
    {
        _getnum(h[i]);
        if(H<h[i])H=h[i];
    }
    for(i=1;i<=H;i++)
        for(j=i;j<=H;j+=i)
        {
            di[++E]=i;
            dnext[E]=dlast[j];
            dlast[j]=E;
        }
    mu[1]=1;
    for(i=2;i<=H;i++)
        pF[i]=true;
    for(i=2;i<=H;i++)
    {
        if(pF[i]==true)
        {
            prime[++tot_prime]=i;
            mu[i]=-1;
        }
        for(j=1;j<=tot_prime&&(k=i*prime[j])<=H;j++)
        {
            pF[k]=false;
            if(i%prime[j]!=0)
                mu[k]=-mu[i];
            else
            {
                mu[k]=0;
                break;
            }
        }
    }
    for(i=1;i<=Q;i++)
    {
        _getnum(k);
        t=F[k]?-1:1;
        F[k]^=1;
        k=h[k];
        c[k]+=t;
        for(j=dlast[k];j>0;j=dnext[j])
        {
            d=di[j];
            ans-=mu[d]*1ll*sc[d]*sc[d];
            sc[d]+=t;
            ans+=mu[d]*1ll*sc[d]*sc[d];
        }
        printf("%I64d\n",(ans-1ll*c[1]*c[1])>>1);
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
using namespace std;
const int maxn=200005;
const int maxh=500005;
const int maxe=7000005;
int N,Q,H,h[maxn];
int E,di[maxe],dnext[maxe],dlast[maxh];
int tot_prime,prime[maxh],mu[maxh];
bool pF[maxh];
long long ans;
int sc[maxh],c[maxh];
bool F[maxn];
inline void _getnum(int &xx)
{
    char tt=getchar();
    while(tt<'0'||tt>'9')tt=getchar();
    for(xx=0;tt>='0'&&tt<='9';tt=getchar())xx=xx*10+(tt-'0');
}
int main()
{
    //freopen("datax.in","r",stdin);
    //freopen("my-2.out","w",stdout);
    int i,j,k,t,d;
    _getnum(N);_getnum(Q);
    for(i=1;i<=N;i++)
    {
        _getnum(h[i]);
        if(H<h[i])H=h[i];
    }
    mu[1]=1;
    for(i=2;i<=H;i++)
        pF[i]=true;
    for(i=2;i<=H;i++)
    {
        if(pF[i]==true)
        {
            prime[++tot_prime]=i;
            mu[i]=-1;
        }
        for(j=1;j<=tot_prime&&(k=i*prime[j])<=H;j++)
        {
            pF[k]=false;
            if(i%prime[j]!=0)
                mu[k]=-mu[i];
            else
            {
                mu[k]=0;
                break;
            }
        }
    }
    for(i=1;i<=H;i++)
    {
        if(mu[i]==0)
            continue;
        for(j=i;j<=H;j+=i)
        {
            di[++E]=i;
            dnext[E]=dlast[j];
            dlast[j]=E;
        }
    }
    for(i=1;i<=Q;i++)
    {
        _getnum(k);F[k]^=1;
        if(F[k]==true)
        {
            k=h[k];c[k]++;
            for(j=dlast[k];j>0;j=dnext[j])
            {
                d=di[j];
                ans+=mu[d]*(sc[d]*2+1);
                sc[d]++;
            }
        }
        else
        {
            k=h[k];c[k]--;
            for(j=dlast[k];j>0;j=dnext[j])
            {
                d=di[j];
                sc[d]--;
                ans-=mu[d]*(sc[d]*2+1);
            }
        }
        printf("%I64d\n",(ans-c[1])>>1);
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
using namespace std;
const int maxn=200005;
const int maxh=500005;
const int maxe=3000005;
int N,Q,H,h[maxn];
int E,di[maxe],dnext[maxe],dlast[maxh];
int tot_prime,prime[maxh],mu[maxh];
bool pF[maxh];
long long ans;
int sc[maxh],c[maxh];
bool F[maxn];
inline void _getnum(int &xx)
{
    char tt=getchar();
    while(tt<'0'||tt>'9')tt=getchar();
    for(xx=0;tt>='0'&&tt<='9';tt=getchar())xx=xx*10+(tt-'0');
}
int main()
{
    //freopen("datax.in","r",stdin);
    //freopen("my-1.out","w",stdout);
    int i,j,k,t,d;
    _getnum(N);_getnum(Q);
    for(i=1;i<=N;i++)
    {
        _getnum(h[i]);
        if(H<h[i])H=h[i];
    }
    mu[1]=1;
    for(i=2;i<=H;i++)
        pF[i]=true;
    for(i=2;i<=H;i++)
    {
        if(pF[i]==true)
        {
            prime[++tot_prime]=i;
            mu[i]=-1;
        }
        for(j=1;j<=tot_prime&&(k=i*prime[j])<=H;j++)
        {
            pF[k]=false;
            if(i%prime[j]!=0)
                mu[k]=-mu[i];
            else
            {
                mu[k]=0;
                break;
            }
        }
    }
    for(i=1;i<=H;i++)
    {
        if(mu[i]==0)
            continue;
        for(j=i;j<=H;j+=i)
        {
            di[++E]=i;
            dnext[E]=dlast[j];
            dlast[j]=E;
        }
    }
    for(i=1;i<=Q;i++)
    {
        _getnum(k);F[k]^=1;
        if(F[k]==true)
        {
            k=h[k];c[k]++;
            for(j=dlast[k];j>0;j=dnext[j])
            {
                d=di[j];
                ans+=mu[d]*((sc[d]<<1)+1);
                sc[d]++;
            }
        }
        else
        {
            k=h[k];c[k]--;
            for(j=dlast[k];j>0;j=dnext[j])
            {
                d=di[j];
                ans-=mu[d]*((sc[d]<<1)-1);
                sc[d]--;
            }
        }
        printf("%I64d\n",(ans-c[1])>>1);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=500010;
int N,M;
int a[maxn];
int prime[maxn],vis[maxn];
int num,cnt[maxn];
bool is_in[maxn];
int sum;
void getprime()
{
    num=0;
    vis[1]=1;
    for(int i=1;i<maxn;i++)
    {
        if(!vis[i])prime[num++]=i;
        for(int j=0;j<num;j++)
        {
            if(i*prime[j]>=maxn)break;
            vis[i*prime[j]]=1;
            if(i%prime[j]==0)break;
        }
    }
}
LL solve(int x)
{
    vector<int> q;
    for(int i=0;i<num&&prime[i]<=x;i++)
    {
        if(x%prime[i]==0)q.push_back(prime[i]);
        while(x%prime[i]==0)x/=prime[i];
        if(!vis[x]){q.push_back(x);break;}
    }
    int len=q.size();
    LL ans=0;
    for(int S=1;S<(1<<len);S++)
    {
        int p=0;
        int u=1;
        for(int i=0;i<len;i++)
            if(S&(1<<i))p++,u*=q[i];
        if(p&1)ans=ans+cnt[u];
        else ans-=cnt[u];
    }
    return sum-ans;
}
void cal(int x,int val)
{
    for(int j=1;j*j<=x;j++)
        if(x%j==0)
        {
            cnt[j]+=val;
            if(x/j!=j)cnt[x/j]+=val;
        }
}
int main()
{
    getprime();
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=N;i++)
            scanf("%d",&a[i]);
        memset(is_in,0,sizeof(is_in));
        LL ans=0;
        sum=0;
        while(M--)
        {
            int x;
            scanf("%d",&x);
            if(is_in[x])
            {
                ans-=solve(a[x]);
                cal(a[x],-1),is_in[x]=0;
                sum--;
            }
            else
            {
                sum++;
                cal(a[x],1),is_in[x]=1;
                ans+=solve(a[x]);
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
using namespace std;
typedef long long LL;
const int maxn=500010;
int N,M;
int a[maxn];
int prime[maxn],vis[maxn];
int num,cnt[maxn];
bool is_in[maxn];
int sum;
void getprime()
{
    num=0;
    vis[1]=1;
    for(int i=1;i<maxn;i++)
    {
        if(!vis[i])prime[num++]=i;
        for(int j=0;j<num;j++)
        {
            if(i*prime[j]>=maxn)break;
            vis[i*prime[j]]=1;
            if(i%prime[j]==0)break;
        }
    }
}
LL solve(int x)
{
    vector<int> q;
    for(int i=0;i<num&&prime[i]<=x;i++)
    {
        if(x%prime[i]==0)q.push_back(prime[i]);
        while(x%prime[i]==0)x/=prime[i];
        if(!vis[x]){q.push_back(x);break;}
    }
    int len=q.size();
    LL ans=0;
    for(int S=1;S<(1<<len);S++)
    {
        int p=0;
        int u=1;
        for(int i=0;i<len;i++)
            if(S&(1<<i))p++,u*=q[i];
        if(p&1)ans=ans+cnt[u];
        else ans-=cnt[u];
    }
    return sum-ans;
}
void cal(int x,int val)
{
    for(int j=1;j*j<=x;j++)
        if(x%j==0)
        {
            cnt[j]+=val;
            if(x/j!=j)cnt[x/j]+=val;
        }
}
int main()
{
    getprime();
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=N;i++)
            scanf("%d",&a[i]);
        memset(is_in,0,sizeof(is_in));
        LL ans=0;
        sum=0;
        while(M--)
        {
            int x;
            scanf("%d",&x);
            if(is_in[x])
            {
				sum--;
				cal(a[x],-1),is_in[x]=0;
                ans-=solve(a[x]);

            }
            else
            {
               	ans+=solve(a[x]);
                cal(a[x],1),is_in[x]=1;
				sum++;
            }
            cout"<<ans<<endl;
        }
    }
    return 0;
}


 By gaolee, contest: Codeforces Round #305 (Div. 1), problem: (C) Mike and Foam, Accepted, #

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=500010;
int N,M;
int a[maxn];
int prime[maxn],vis[maxn];
int num,cnt[maxn];
bool is_in[maxn];
int sum;
void getprime()
{
    num=0;
    vis[1]=1;
    for(int i=1;i<maxn;i++)
    {
        if(!vis[i])prime[num++]=i;
        for(int j=0;j<num;j++)
        {
            if(i*prime[j]>=maxn)break;
            vis[i*prime[j]]=1;
            if(i%prime[j]==0)break;
        }
    }
}
LL solve(int x)
{
    vector<int> q;
    for(int i=0;i<num&&prime[i]<=x;i++)
    {
        if(x%prime[i]==0)q.push_back(prime[i]);
        while(x%prime[i]==0)x/=prime[i];
        if(!vis[x]){q.push_back(x);break;}
    }
    int len=q.size();
    LL ans=0;
    for(int S=1;S<(1<<len);S++)
    {
        int p=0;
        int u=1;
        for(int i=0;i<len;i++)
            if(S&(1<<i))p++,u*=q[i];
        if(p&1)ans=ans+cnt[u];
        else ans-=cnt[u];
    }
    if(ans)ans--;
    return sum-1-ans;
}
void cal(int x,int val)
{
    for(int j=1;j*j<=x;j++)
        if(x%j==0)
        {
            cnt[j]+=val;
            if(x/j!=j)cnt[x/j]+=val;
        }
}
int main()
{
    getprime();
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=N;i++)
            scanf("%d",&a[i]);
        memset(is_in,0,sizeof(is_in));
        LL ans=0;
        sum=0;
        while(M--)
        {
            int x;
            scanf("%d",&x);
            if(is_in[x])
            {
                ans-=solve(a[x]);
                cal(a[x],-1),is_in[x]=0;
                sum--;
            }
            else
            {
                sum++;
                cal(a[x],1),is_in[x]=1;
                ans+=solve(a[x]);
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


import sys
input = sys.stdin.readline
def main():
	for t in range(int(input())):
		n = int(input())
		a = list(map(int,input().split()))
		odd, even = [], []
		for i in range(2*n):
			x = a[i]
			if x%2 == 0:
				even +=[[i+1,x]]
			else:
				odd +=[[i+1,x]]
		if len(odd)%2 == 1:
			odd = odd[:len(odd)-1]
			even = even[:len(even)-1]
		else:
			odd = odd[:len(odd)-2]
		i = 0
		while 2*i <len(even):
			print(even[2*i][0],even[2*i+1][0])
			i+=1
		i = 0
		while 2*i <len(odd):
			print(odd[2*i][0], odd[2*i+1][0])
			i+=1
main()


import sys
input = sys.stdin.readline
def main():
	for t in range(int(input())):
		n = int(input())
		a = list(map(int,input().split()))
		odd, even = [], []
		for i in range(2*n):
			x = a[i]
			if x%2 == 0:
				even +=[[i+1,x]]
			else:
				odd +=[[i+1,x]]
		if len(odd)%2 == 1:
			odd = odd[:len(odd)-1]
			even = even[:len(even)-1]
		elif len(odd) >1:
			odd = odd[:len(odd)-2]
		else:
			even = even[:len(even)-2]
		i = 0
		while 2*i <len(even):
			print(even[2*i][0],even[2*i+1][0])
			i+=1
		i = 0
		while 2*i <len(odd):
			print(odd[2*i][0], odd[2*i+1][0])
			i+=1
main()


import sys
input = sys.stdin.readline
def main():
	for t in range(int(input())):
		n = int(input())
		a = list(map(int,input().split()))
		odd, even = [], []
		for i in range(2*n):
			if a[i]%2 == 0:
				even +=[i+1]
			else:
				odd +=[i+1]
		if len(odd)%2 == 1:
			odd = odd[:len(odd)-1]
			even = even[:len(even)-1]
		elif len(odd) >1:
			odd = odd[:len(odd)-2]
		else:
			even = even[:len(even)-2]
		i = 0
		while 2*i <len(even):
			print(even[2*i],even[2*i+1])
			i+=1
		i = 0
		while 2*i <len(odd):
			print(odd[2*i], odd[2*i+1])
			i+=1
main()


t=int(input())
for _ in range(t):
    n=int(input())
    x=list(map(int,input().split()))
    l=len(x)
    o=[]
    e=[]
    for i in range(l):
        if x[i]%2==0:
            e.append(i+1)
        else:
            o.append(i+1)
    l1=len(o)
    l2=len(e)
    if l1==0:
        for i in range(0,l2-1,2):
            print(o[i],o[i+1])
    elif l2==0:
        for i in range(0,l1-1,2):
            print(e[i],e[i+1])
    if l1%2==0 and l2%2==0:
        for i in range(0,l1-2,2):
            print(o[i],o[i+1])
        for i in range(0,l2,2):
            print(e[i],e[i+1])
    else:
        for i in range(0,l1-1,2):
            print(o[i],o[i+1])
        for i in range(0,l2-1,2):
            print(e[i],e[i+1])


t=int(input())
for _ in range(t):
    n=int(input())
    x=list(map(int,input().split()))
    l=len(x)
    o=[]
    e=[]
    for i in range(l):
        if x[i]%2==0:
            e.append(i+1)
        else:
            o.append(i+1)

    l1=len(o)
    l2=len(e)
    if l1==0:
        l2=l2-2
    elif l2==0:
        l1=l-2
    elif l1%2==0 and l2%2==0:
        l1=l1-2
    else:
        l1=l1-1
        l2=l2-1
    for i in range(0,l1,2):
        print(o[i],o[i+1])
    for i in range(0,l2,2):
        print(e[i],e[i+1])


# -*- coding: utf-8 -*-
"""
#k,m=map(int,input().split())
t=int(input())
for _ in range(t):
    n=int(input())
    x=list(map(int,input().split()))

"""
t=int(input())
for _ in range(t):
    n=int(input())
    x=list(map(int,input().split()))
    o=[]
    e=[]
    for i in x:
        if i%2==0:
            e.append(i)
        else:
            o.append(i)
    l1=len(o)
    l2=len(e)
    if l1==0:
        for i in range(0,(l2//2)-1,2):
            print(o[i],o[i+1])
    elif l2==0:
        for i in range(0,(l1//2)-1,2):
            print(e[i],e[i+1])
    if l1%2==0 and l2%2==0:
        for i in range(0,(l1//2)-1,2):
            print(o[i],o[i+1])
        for i in range(0,(l2//2),2):
            print(e[i],e[i+1])
    else:
        for i in range(0,(l1//2),2):
            print(o[i],o[i+1])
        for i in range(0,(l2//2),2):
            print(e[i],e[i+1])


# -*- coding: utf-8 -*-
"""
#k,m=map(int,input().split())
t=int(input())
for _ in range(t):
    n=int(input())
    x=list(map(int,input().split()))

"""
t=int(input())
for _ in range(t):
    n=int(input())
    x=list(map(int,input().split()))
    l=len(x)
    o=[]
    e=[]
    for i in range(l):
        if x[i]%2==0:
            e.append(i+1)
        else:
            o.append(i+1)
    l1=len(o)
    l2=len(e)
    if l1==0:
        for i in range(0,(l2//2)-1,2):
            print(o[i],o[i+1])
    elif l2==0:
        for i in range(0,(l1//2)-1,2):
            print(e[i],e[i+1])
    if l1%2==0 and l2%2==0:
        for i in range(0,(l1//2)-1,2):
            print(o[i],o[i+1])
        for i in range(0,(l2//2),2):
            print(e[i],e[i+1])
    else:
        for i in range(0,(l1//2),2):
            print(o[i],o[i+1])
        for i in range(0,(l2//2),2):
            print(e[i],e[i+1])


#!/usr/bin/env python3
import sys

def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        array = list(map(int, input().split()))
        solve(n, array)

def solve(n, array):
    odd = []
    even = []
    for (i, v) in enumerate(array):
        if v % 2 == 0:
            even.append(i)
        else:
            odd.append(i)
    if len(even) % 2 == 0:
        for indx in range(len(even) // 2):
            print("{} {}".format(even[2 * indx], even[2 * indx + 1]))
        for indx in range(len(odd) // 2 - 1):
            print("{} {}".format(odd[2 * indx], odd[2 * indx + 1]))
    else:
        for indx in range(len(even) // 2):
            print("{} {}".format(even[2 * indx], even[2 * indx + 1]))
        for indx in range(len(odd) // 2):
            print("{} {}".format(odd[2 * indx], odd[2 * indx + 1]))

if __name__ == '__main__':
    main()


#!/usr/bin/env python3
import sys

def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        array = list(map(int, input().split()))
        solve(n, array)

def solve(n, array):
    odd = []
    even = []
    for v in array:
        if v % 2 == 0:
            even.append(v)
        else:
            odd.append(v)
    if len(even) % 2 == 0:
        for indx in range(len(even) // 2):
            print("{} {}".format(even[2 * indx], even[2 * indx + 1]))
        for indx in range(len(odd) // 2 - 1):
            print("{} {}".format(odd[2 * indx], odd[2 * indx + 1]))
    else:
        for indx in range(len(even) // 2):
            print("{} {}".format(even[2 * indx], even[2 * indx + 1]))
        for indx in range(len(odd) // 2):
            print("{} {}".format(odd[2 * indx], odd[2 * indx + 1]))

if __name__ == '__main__':
    main()


#!/usr/bin/env python3
import sys

def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        array = list(map(int, input().split()))
        solve(n, array)

def solve(n, array):
    odd = []
    even = []
    for (i, v) in enumerate(array):
        if v % 2 == 0:
            even.append(i+1)
        else:
            odd.append(i+1)
    if len(even) % 2 == 0:
        for indx in range(len(even) // 2 - (1 if len(odd) == 0 else 0)):
            print("{} {}".format(even[2 * indx], even[2 * indx + 1]))
        for indx in range(len(odd) // 2):
            print("{} {}".format(odd[2 * indx], odd[2 * indx + 1]))
    else:
        for indx in range(len(even) // 2):
            print("{} {}".format(even[2 * indx], even[2 * indx + 1]))
        for indx in range(len(odd) // 2):
            print("{} {}".format(odd[2 * indx], odd[2 * indx + 1]))

if __name__ == '__main__':
    main()


#!/usr/bin/env python3
import sys

def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        array = list(map(int, input().split()))
        solve(n, array)

def solve(n, array):
    odd = []
    even = []
    for (i, v) in enumerate(array):
        if v % 2 == 0:
            even.append(i+1)
        else:
            odd.append(i+1)
    if len(even) % 2 == 0:
        for indx in range(len(even) // 2):
            print("{} {}".format(even[2 * indx], even[2 * indx + 1]))
        for indx in range(len(odd) // 2 - 1):
            print("{} {}".format(odd[2 * indx], odd[2 * indx + 1]))
    else:
        for indx in range(len(even) // 2):
            print("{} {}".format(even[2 * indx], even[2 * indx + 1]))
        for indx in range(len(odd) // 2):
            print("{} {}".format(odd[2 * indx], odd[2 * indx + 1]))

if __name__ == '__main__':
    main()


#!/usr/bin/env python3
import sys

def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        array = list(map(int, input().split()))
        solve(n, array)

def solve(n, array):
    odd = []
    even = []
    for (i, v) in enumerate(array):
        if v % 2 == 0:
            even.append(i+1)
        else:
            odd.append(i+1)
    if len(even) % 2 == 0:
        for indx in range(len(even) // 2 - (len(odd) != 0)):
            print("{} {}".format(even[2 * indx], even[2 * indx + 1]))
        for indx in range(len(odd) // 2):
            print("{} {}".format(odd[2 * indx], odd[2 * indx + 1]))
    else:
        for indx in range(len(even) // 2):
            print("{} {}".format(even[2 * indx], even[2 * indx + 1]))
        for indx in range(len(odd) // 2):
            print("{} {}".format(odd[2 * indx], odd[2 * indx + 1]))

if __name__ == '__main__':
    main()


#!/usr/bin/env python3
import sys

def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        array = list(map(int, input().split()))
        solve(n, array)

def solve(n, array):
    odd = []
    even = []
    for (i, v) in enumerate(array):
        if v % 2 == 0:
            even.append(i+1)
        else:
            odd.append(i+1)
    if len(even) % 2 == 0:
        for indx in range(len(even) // 2 - (len(odd) == 0)):
            print("{} {}".format(even[2 * indx], even[2 * indx + 1]))
        for indx in range(len(odd) // 2 - 1):
            print("{} {}".format(odd[2 * indx], odd[2 * indx + 1]))
    else:
        for indx in range(len(even) // 2):
            print("{} {}".format(even[2 * indx], even[2 * indx + 1]))
        for indx in range(len(odd) // 2):
            print("{} {}".format(odd[2 * indx], odd[2 * indx + 1]))

if __name__ == '__main__':
    main()


import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	even = []
	odd = []

	for i in range(2*n):
		v = arr[i]
		if v%2:
			odd.append( i+1 )
		else:
			even.append( i+1 )

	len_e = len(even)
	len_e = len_e - len_e%2
	len_o = len(odd)
	len_o = len_o - len_o%2

	res = []
	for i in range(0,len_e,2):
		res.append( (even[i], even[i+1]) )
	for j in range(0, len_o, 2):
		res.append( ( odd[j], odd[j+1] ) )

	for i in range(n-1):
		print( res[i][0], res[i][1] )


import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	lst = [ (i+1,v) for i,v in enumerate( arr ) ]
	even = []
	odd = []

	for i,v in lst:
		if v%2:
			odd.append( (i,v) )
		else:
			even.append( (i,v) )

	len_e = len(even)
	len_o = len(odd)
	even.sort(key = lambda x: x[1])
	odd.sort(key = lambda x: x[1])

	if len_e%2 == 1:
			even = even[1:]
			odd = odd[1:]
	else:
		if len_o > 1:
			odd = odd[2:]
		else:
			even = even[2:]

	if len(even) > 0:
		for i in range(0,len(even),2):
			print( even[i][0], even[~i][0] )
	if len(odd) > 0:
		for j in range(0, len(odd),2):
			print( odd[j][0], odd[~j][0] )


import math
for _ in range(int(input())):
	n = int(input())
	lst = [ (i+1,v) for i,v in enumerate( list(map(int, input().split())) ) ]
	even = []
	odd = []

	for i,v in lst:
		if v%2:
			odd.append( (i,v) )
		else:
			even.append( (i,v) )

	len_e = len(even)
	len_o = len(odd)
	even.sort(key = lambda x: x[1])
	odd.sort(key = lambda x: x[1])

	if len_e%2 == 1:
		if len_e%2:
			even = even[1:]
		if len_o%2:
			odd = odd[1:]
	else:
		odd = odd[2:]

	# print( (len(even) + len(odd)) == (2*n - 2) )
	for i in range(0,len(even),2):
		print( even[i][0], even[~i][0] )
	for j in range(0, len(odd),2):
		print( odd[j][0], odd[~j][0] )


import math
a=int(input())
for i in range(0,a):
    b=int(input())
    arr=list(map(int,input().split()))
    eveni=[]
    oddi=[]
    for i in range(0,len(arr)):
        if(arr[i]%2==0):
            eveni.append(i)
        else:
            oddi.append(i)
    st=len(oddi)%2
    for i in range(0,len(eveni)-st-1,2):
        print(eveni[i]+1,eveni[i+1]+1)
    for i in range(0,len(oddi)-st-1,2):
        print(oddi[i]+1,oddi[i+1]+1)


import math
a=int(input())
for i in range(0,a):
    b=int(input())
    arr=list(map(int,input().split()))
    eveni=[]
    oddi=[]
    for i in range(0,len(arr)):
        if(arr[i]%2==0):
            eveni.append(i)
        else:
            oddi.append(i)
    st=len(oddi)%2
    pt=len(oddi)%2
    for i in range(0,len(eveni)-st-1,2):
        if(pt==0):
            pt=1
        else:
            print(eveni[i]+1,eveni[i+1]+1)
    for i in range(0,len(oddi)-st-1,2):
        if(pt==0):
            pt=1
        else:
            print(oddi[i]+1,oddi[i+1]+1)


import math
a=int(input())
for i in range(0,a):
    b=int(input())
    arr=list(map(int,input().split()))
    odd=dict()
    even=dict()
    eveni=[]
    oddi=[]
    for i in range(0,len(arr)):
        if(arr[i]%2==0):
            even[arr[i]]=i
            eveni.append(i)
        else:
            odd[arr[i]]=i
            oddi.append(i)
    st=len(odd)%2
    for i in range(0,len(eveni)-st-1,2):
        print(eveni[i]+1,eveni[i+1]+1)
    for i in range(0,len(odd)-st-1,2):
        print(oddi[i]+1,oddi[i+1]+1)


import math
a=int(input())
for i in range(0,a):
    b=int(input())
    arr=list(map(int,input().split()))
    eveni=[]
    oddi=[]
    for i in range(0,len(arr)):
        if(arr[i]%2==0):
            eveni.append(i)
        else:
            oddi.append(i)
    st=len(oddi)%2
    for i in range(0,len(eveni)-st-1,2):
        if(st==0):
            st=1
        else:
            print(eveni[i]+1,eveni[i+1]+1)
    for i in range(0,len(oddi)-st-1,2):
        if(st==0):
            st=1
        else:
            print(oddi[i]+1,oddi[i+1]+1)


for _ in range(int(input())):
    n=int(input())
    a = list(map(int, input().split(' ')))
    for i in a:
        j = a.index(i) + 1
        b = False
        while j < a.__len__() and not b:
            if not (i + a[j]) % 2:
                b = True
                print(i, a[j])
                a.remove(a[j])
            j = j + 1
        if (a.__len__() + (n-1) == n*2):
            break


for _ in range(int(input())):
    n=int(input())
    a = list(map(int, input().split(' ')))
    for i in a:
        j = a.index(i) + 1
        b = False
        while j < a.__len__() and not b:
            if not (i + a[j]) % 2:
                b = True
                print(a.index(i),j)
                a.remove(a[j])
            j = j + 1
        if (a.__len__() + (n-1) == n*2):
            break


for _ in range(int(input())):
    n=int(input())
    c=0
    a = list(map(int, input().split(' ')))
    for i in a:
        j = a.index(i) + 1
        b = False
        while j < a.__len__() and not b and not a[j]==0.2:
            if not (i + a[j]) % 2:
                c=c+1
                b = True
                print(a.index(i)+1,j+1)
                a[j]=0.2
                a[a.index(i)]=0.2
            j = j + 1
        if ((n*2)-2 == c*2):
            break


for _ in range(int(input())):
    m = []
    n = int(input())
    a = list(map(int, input().split(' ')))
    for i in a:
        j = a.index(i) + 1
        b = False
        while j < a.__len__() and not b and not i == 0.2 :
            if not (i + a[j]) % 2 and not m.__contains__(sorted([a[j],i])):
                b = True
                print(a.index(i) + 1, j + 1)
                m.append(sorted([a[j],i]))
                a[j] = 0.2
                a[a.index(i)] = 0.2
            j = j + 1
        if n-1 == m.__len__():
            break


for _ in range(int(input())):
    n=int(input())
    c=0
    a = list(map(int, input().split(' ')))
    for i in a:
        j = a.index(i) + 1
        b = False
        while j < a.__len__() and not b:
            if not (i + a[j]) % 2:
                c=c+1
                b = True
                print(a.index(i)+1,j+1)
                a[j]=0.2
            j = j + 1
        if ((n*2)-2 == c*2):
            break


for _ in range(int(input())):
    n=int(input())
    a = list(map(int, input().split(' ')))
    for i in a:
        j = a.index(i) + 1
        b = False
        while j < a.__len__() and not b:
            if not (i + a[j]) % 2:
                b = True
                print(a.index(i)+1,j+1)
                a.remove(a[j])
            j = j + 1
        if (a.__len__() + (n-1) == n*2):
            break


for _ in range(int(input())):
    n=int(input())
    a = list(map(int, input().split(' ')))
    for i in a:
        j = a.index(i) + 1
        b = False
        while j < a.__len__() and not b:
            if not (i + a[j]) % 2:
                b = True
                print(a.index(i)+1,j+1)
                a[j]=0.2
            j = j + 1
        if (a.__len__() + (n-1) == n*2):
            break


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split(' ')))
    p = -1
    m = -1
    for i in range(n * 2):
        if a[i] % 2:
            if m > -1:
                print(m + 1, i + 1)
                m = -1
            else:
                m = i
        else:
            if p > -1:
                print(p + 1, i + 1)
                p = -1
            else:
                p = i
        if i == (n-1)*2:
            break


m=[]
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split(' ')))
    for i in a:
        j = a.index(i) + 1
        b = False
        while j < a.__len__() and not b and not i == 0.2 :
            if not (i + a[j]) % 2 and not m.__contains__(sorted([a[j],i])):
                b = True
                print(a.index(i) + 1, j + 1)
                m.append(sorted([a[j],i]))
                a[j] = 0.2
                a[a.index(i)] = 0.2
            j = j + 1
        if a.__len__()-2 == m.__len__():
            break


for _ in range(int(input())):
	n=int(input())
	a=list(map(int,input().strip().split()))
	odd=[]
	even=[]
	for i in range(2*n):
		if a[i]%2==0:
			even.append(i+1)
		else:
			odd.append(i+1)
	cnt=0
	for i in range(1,len(even),2):
		if cnt >= (n-1):
			break
		print(even[i-1],even[i])
		cnt+=1

	for i in range(1,len(odd),2):
		if cnt >= (n-1):
			break
		print(odd[i-1],odd[i])
		cnt+=1


for _ in range(int(input())):
	n=int(input())
	a=list(map(int,input().strip().split()))
	odd=[]
	even=[]
	for i in range(2*n):
		if a[i]%2==0:
			even.append(i+1)
		else:
			odd.append(i+1)
	cnt=0
	for i in range(1,len(odd),2):
		if cnt >= (n-1):
			break
		print(odd[i-1],odd[i])
		cnt+=1


for _ in range(int(input())):
	n=int(input())
	a=list(map(int,input().strip().split()))
	odd=[]
	even=[]
	for i in range(2*n):
		if a[i]%2==0:
			even.append(i+1)
		else:
			odd.append(i+1)
	cnt=0
	for i in range(1,len(even),2):
		if cnt >= (n-1):
			break
		print(even[i-1],even[i])
		cnt+=1


#Name:S.M.MILOY
#Department Of CSE,BRUR
#a,b=list(map(int,input().split()))
#l=list(map(int,input().split(' ')))
#n=int(z())
z=input
#for i in range(n):
from math import gcd

n=int(z())

for _ in range(n):
    x=int(input())
    l=list(map(int,input().split()))
    odd=0

    even=0
    o=[]
    e=[]
    kp=2*x
    m=1
    for i in range(kp):
        if l[0]%2==0:
            even+=1
            e.append(l.index(l[0])+m)
            l.remove(l[0])
            m+=1

        else:
            odd+=1
            o.append(l.index(l[0])+m)
            l.remove(l[0])
            m+=1

    f=odd
    k=even
    x=x-1
    fh=0

    for i in range(0,f,2):
        try:
            print(o[i],o[i+1])
            fh+=1
            if fh>=x:
                break
        except:
            break
    for i in range(0,k,2):

        try:
            print(e[i],e[i+1])
            fh+=1
            if fh>=x:
                break
        except:
            break


#Name:S.M.MILOY
#Department Of CSE,BRUR
#a,b=list(map(int,input().split()))
#l=list(map(int,input().split(' ')))
#n=int(z())
z=input
#for i in range(n):
from math import gcd

n=int(z())

for _ in range(n):
    x=int(input())
    l=list(map(int,input().split()))
    odd=0

    even=0
    o=[]
    e=[]
    kp=2*x
    m=1
    for i in range(kp):
        if l[0]%2==0:
            even+=1
            e.append(l.index(l[0])+m)
            l.remove(l[0])
            m+=1

        else:
            odd+=1
            o.append(l.index(l[0])+m)
            l.remove(l[0])
            m+=1

    f=odd
    k=even
    x=x-1
    fh=0

    for i in range(0,f,2):
        try:
            print(o[i],o[i+1])
            fh+=1
            if fh>=x:
                break
        except:
            pass
    for i in range(0,k,2):

        try:
            print(e[i],e[i+1])
            fh+=1
            if fh>=x:
                break
        except:
            pass


#Name:S.M.MILOY
#Department Of CSE,BRUR
#a,b=list(map(int,input().split()))
#l=list(map(int,input().split(' ')))
#n=int(z())
z=input
#for i in range(n):
from math import gcd

n=int(z())

for _ in range(n):
    x=int(input())
    l=list(map(int,input().split()))
    odd=0
    even=0
    o=[]
    e=[]
    kp=2*x
    m=1
    for i in range(kp):
        if l[0]%2==0:
            even+=1
            e.append(l.index(l[0])+m)
            l.remove(l[0])
            m+=1
        else:
            odd+=1
            o.append(l.index(l[0])+m)
            l.remove(l[0])
            m+=1

    f=odd
    k=even
    x=x-1
    fh=0

    for i in range(0,f,2):
        try:
            print(o[i],o[i+1])
            fh+=1
            if fh==x:
                break
        except:
            break

    for i in range(k-1,-1,-2):

        try:
            if fh==x:
                break
            print(e[i],e[i-1])
            fh+=1

        except:
            break


#Name:S.M.MILOY
#Department Of CSE,BRUR
#a,b=list(map(int,input().split()))
#l=list(map(int,input().split(' ')))
#n=int(z())
z=input
#for i in range(n):
from math import gcd

n=int(z())

for _ in range(n):
    x=int(input())
    l=list(map(int,input().split()))
    odd=0
    even=0
    o=[]
    e=[]
    kp=2*x
    m=1
    for i in range(kp):
        if l[0]%2==0:
            even+=1
            e.append(l.index(l[0])+m)
            l.remove(l[0])
            m+=1
        else:
            odd+=1
            o.append(l.index(l[0])+m)
            l.remove(l[0])
            m+=1

    f=odd
    k=even
    x=x-1
    fh=0

    for i in range(0,f,2):
        try:
            print(o[i],o[i+1])
            fh+=1
            if fh==x:
                break
        except:
            break

    for i in range(k-1,-1,-2):

        try:
            print(e[i],e[i-1])
            fh+=1
            if fh==x:
                break
        except:
            break


#Name:S.M.MILOY
#Department Of CSE,BRUR
#a,b=list(map(int,input().split()))
#l=list(map(int,input().split(' ')))
#n=int(z())
z=input
#for i in range(n):
from math import gcd

n=int(z())

for _ in range(n):
    x=int(input())
    l=list(map(int,input().split()))
    odd=[]

    even=[]
    o=[]
    e=[]
    for i in l:
        if i%2==0:
            even.append(i)
            e.append(l.index(i)+1)
        else:
            odd.append(i)
            o.append(l.index(i)+1)

    f=len(odd)
    k=len(even)
    x=x-1
    fh=0
    for i in range(0,f//2,2):
        print(o[i],o[i+1])
        fh+=1
        if fh>=x:
            break
    for i in range(0,k//2,2):
        print(e[i],e[i+1])
        fh+=1
        if fh>=x:
            break


#Name:S.M.MILOY
#Department Of CSE,BRUR
#a,b=list(map(int,input().split()))
#l=list(map(int,input().split(' ')))
#n=int(z())
z=input
#for i in range(n):
from math import gcd

n=int(z())

for _ in range(n):
    x=int(input())
    l=list(map(int,input().split()))
    odd=0

    even=0
    o=[]
    e=[]
    kp=2*x
    m=1
    for i in range(kp):
        if l[0]%2==0:
            even+=1
            e.append(l.index(l[0])+m)
            l.remove(l[0])
            m+=1

        else:
            odd+=1
            o.append(l.index(l[0])+m)
            l.remove(l[0])
            m+=1

    f=odd
    k=even
    x=x-1
    fh=0

    for i in range(0,f,2):
        try:
            print(o[i],o[i+1])
            fh+=1
            if fh>=x:
                break
        except:
            pass
    for i in range(0,k,2):

        try:
            if fh>=x:
                break
            print(e[i],e[i+1])
            fh+=1
            if fh>=x:
                break
        except:
            pass


for i in range(int(input())):
	n = int(input())
	a= list(map(int,input().split()))
	even=[]
	odd=[]
	for i in range(2*n):
		if a[i]%2==0:
			even.append(i+1)
		else:
			odd.append(i+1)

	if len(even)%2==0 :
		ans= even[:-2]+odd
	else:
		ans= even[:-1]+odd[:-1]
	for i in range(0,len(ans)-1,2):
		print(ans[i],ans[i+1])


for i in range(int(input())):
	n = int(input())
	a= list(map(int,input().split()))
	even=[]
	odd=[]
	for i in range(2*n):
		if a[i]%2==0:
			even.append(i)
		else:
			odd.append(i)

	if len(even)%2==0 :
		ans= even[:-2]+odd
	else:
		ans= even[:-1]+odd[:-1]
	for i in range(0,len(ans)-1,2):
		print(ans[i],ans[i+1])


for i in range(int(input())):
	n = int(input())
	a= list(map(int,input().split()))
	even=[]
	odd=[]
	for i in range(2*n):
		if a[i]%2==0:
			even.append(i)
		else:
			odd.append(i)
	print(even)
	print(odd)

	if len(even)%2==0 :
		ans= even[:-2]+odd
	else:
		ans= even[:-1]+odd[:-1]
	for i in range(0,len(ans)-1,2):
		print(ans[i],ans[i+1])


for i in range(int(input())):
	n = int(input())
	a= list(map(int,input().split()))
	ans=[]
	for i in range(2*n-1):
		for j in range(i+1,2*n):
			if (a[i]+a[j]) % 2 == 0 and a[i] > 0 and a[j] > 0:
				a[i]=-1
				a[j]=-1
				ans.append([i,j])
				break
	for i in range(n-1):
		print(ans[i][0]+1,ans[i][1]+1);


for i in range(int(input())):
	n = int(input())
	a= list(map(int,input().split()))
	even=[]
	odd=[]
	for i in range(2*n):
		if a[i]%2==0:
			even.append(i+1)
		else:
			odd.append(i+1)

	if len(even)%2==0 :
		ans= even+odd
	else:
		ans= even[:-1]+odd[:-1]

	count=0
	while(count<2*(n-1)):
		print(ans[count],ans[count+1])
		count=count+2


t=int(input());
odd_flag=0;

for i in range(t):
    n=int(input());
    a=[int(x) for x in input().split()];
    ct=0;
    odd_flag=0;
    even_flag=0;
    for j in range(2*n+1):
        if a[j]%2>0:
            if odd_flag==0:
                odd_stack=j;
                odd_flag=1;
            else:
                print(odd_stack+1,j+1);
                ct=ct+1;
                odd_flag=0;
        else:
            if even_flag==0:
                even_stack=j;
                even_flag=1;
            else:
                print(even_stack+1,j+1);
                ct=ct+1;
                even_flag=0;
        if ct==n-1:
            break;


import math

t=int(input());
odd_flag=0;

for i in range(t):
    n=int(input());
    a=[int(x) for x in input().split()];
    ct=0;
    use_flag=[0]*2*n;
    for j in range(2*n+1):
        if use_flag[j]==0:
            if a[j]%2>0:
                odd_flag=1;
            else:
                odd_flag=0;
            for k in range(j+1,j+3):
                if a[k]%2==odd_flag and use_flag[k]==0:
                    print(j+1,k+1);
                    use_flag[j]=1;
                    use_flag[k]=1;
                    ct+=1;
                    break;
            if ct==n-1:
                break;


t=int(input());
odd_flag=0;

for i in range(t):
    n=int(input());
    a=[int(x) for x in input().split()];
    ct=0;
    use_flag=[0]*2*n;
    for j in range(2*n+1):
        if use_flag[j]==0:
            if a[j]%2>0:
                odd_flag=1;
            else:
                odd_flag=0;
            for k in range(j+1,2*n+1):
                if a[k]%2==odd_flag and use_flag[k]==0:
                    print(j+1,k+1);
                    use_flag[j]=1;
                    use_flag[k]=1;
                    ct+=1;
                    break;
            if ct==n-1:
                break;


t=int(input());
odd_flag=0;

for i in range(t):
    n=int(input());
    a=[int(x) for x in input().split()];
    ct=0;
    for j in range(2*n+1):
        if a[j]>0:
            if a[j]%2>0:
                odd_flag=1;
            else:
                odd_flag=0;
            for k in range(j+1,2*n+1):
                if a[k]%2==odd_flag and a[k]>0:
                    print(j+1,k+1);
                    a[j]=0;
                    a[k]=0;
                    ct+=1;
                    break;
            if ct==n-1:
                break;


def list_input(): return list(map(int, input().split()))

def multiple_input(): return map(int, input().split())

for _ in range(int(input())):
    n = int(input())
    a = list_input()
    even, odd = [], []
    for i in range(len(a)):
        if a[i] % 2 == 0:
            even.append(i)
        else:
            odd.append(i)
    #print(odd, even)
    count = 0
    flag = 0
    for i in range(0, len(odd)//2):
        print(odd[2*i] + 1, odd[2*i+1] + 1)
        count += 1
        if count == n-1:
            flag = 1
            break
    if flag == 0:
        for i in range(0, len(even)//2):
            print(even[2*i] + 1, even[2*i+1] + 1)
            count += 1
            if count == n-1:
                break


def list_input(): return list(map(int, input().split()))

def multiple_input(): return map(int, input().split())

for _ in range(int(input())):
    n = int(input())
    a = list_input()
    even, odd = [], []
    for i in range(len(a)):
        if a[i] % 2 == 0:
            even.append(i)
        else:
            odd.append(i)
    #print(odd, even)
    for i in range(0, len(odd)//2, 2):
        print(odd[i], odd[i+1])
    for i in range(0, len(even)//2, 2):
        print(even[i], even[i+1])


def list_input(): return list(map(int, input().split()))

def multiple_input(): return map(int, input().split())

for _ in range(int(input())):
    n = int(input())
    a = list_input()
    even, odd = [], []
    for i in range(len(a)):
        if a[i] % 2 == 0:
            even.append(i)
        else:
            odd.append(i)
    #print(odd, even)
    for i in range(0, len(odd)//2, 2):
        print(odd[i] + 1, odd[i+1] + 1)
    for i in range(0, len(even)//2, 2):
        print(even[i] + 1, even[i+1] + 1)


def list_input(): return list(map(int, input().split()))

def multiple_input(): return map(int, input().split())

for _ in range(int(input())):
    n = int(input())
    a = list_input()
    even, odd = [], []
    for i in a:
        if i % 2 == 0:
            even.append(i)
        else:
            odd.append(i)
    for i in range(0, len(odd)//2, 2):
        print(odd[i], odd[i+1])
    for i in range(0, len(even)//2, 2):
        print(even[i], even[i+1])


for t in range(int(input())):
    n=int(input())
    lst=list(map(int,input().split()))
    even=[]
    odd=[]
    for i in range(len(lst)):
        if(lst[i]%2==0):
            even.append([lst[i],i])
        else:
            odd.append([lst[i],i])

    l1=len(even)
    l2=len(odd)

    flag=0
    if(l1%2==0 and l2%2==0):
        flag=1
    elif((l1-1)%2==0 and (l2-1)%2==0):
        flag=2

    if(flag==1):
        a=min(odd)
        odd.remove(a)
        a=min(odd)
        odd.remove(a)
        if(len(odd)!=0):
            if(len(odd)==1):
                print(odd[0][1]+1)
            else:
                for i in range(0,len(odd),2):
                    print((odd[i][1])+1,(odd[i+1][1])+1)
        if(len(even)!=0):
            if(len(even)==1):
                print(even[0][1]+1)
            else:
                for i in range(0,len(even),2):
                    print((even[i][1])+1,(even[i+1][1])+1)

    elif(flag==2):
        a=min(odd)
        b=min(even)
        odd.remove(a)
        even.remove(b)
        if(len(odd)!=0):
            if(len(odd)==1):
                print(odd[0][1]+1)
            else:
                for i in range(0,len(odd),2):
                    print((odd[i][1])+1,(odd[i+1][1])+1)
        if(len(even)!=0):
            if(len(even)==1):
                print(even[0][1]+1)
            else:
                for i in range(0,len(even),2):
                    print((even[i][1])+1,(even[i+1][1])+1)


for t in range(int(input())):
    n=int(input())
    lst=list(map(int,input().split()))
    even=[]
    odd=[]
    for i in range(len(lst)):
        if(lst[i]%2==0):
            even.append([lst[i],i])
        else:
            odd.append([lst[i],i])

    l1=len(even)
    l2=len(odd)

    flag=0
    if(l1%2==0 and l2%2==0):
        flag=1
    elif((l1-1)%2==0 and (l2-1)%2==0):
        flag=2

    if(flag==1):
        a=min(odd)
        odd.remove(a)
        a=min(odd)
        odd.remove(a)
        c=0
        for i in range(len(even)):
            print(even[i][1]+1,end=" ")
            c+=1
            if(c%2==0):
                print()
        for i in range(len(odd)):
            print(odd[i][1]+1,end=" ")
            c+=1
            if(c%2==0):
                print()

    elif(flag==2):
        a=min(odd)
        b=min(even)
        odd.remove(a)
        even.remove(b)
        c=0
        for i in range(len(even)):
            print(even[i][1]+1,end=" ")
            c+=1
            if(c%2==0):
                print()
        for i in range(len(odd)):
            print(odd[i][1]+1,end=" ")
            c+=1
            if(c%2==0):
                print()


for t in range(int(input())):
    n=int(input())
    lst=list(map(int,input().split()))
    even=[]
    odd=[]
    for i in range(len(lst)):
        if(lst[i]%2==0):
            even.append([lst[i],i])
        else:
            odd.append([lst[i],i])

    l1=len(even)
    l2=len(odd)

    flag=0
    if(l1%2==0 and l2%2==0):
        flag=1
    elif((l1-1)%2==0 and (l2-1)%2==0):
        flag=2

    if(flag==1):
        a=min(odd)
        odd.remove(a)
        a=min(odd)
        odd.remove(a)
        #print(len(even),len(odd))
        #print(even)
        #print(odd)
        if(len(odd)!=0):
            for i in range(0,len(odd),2):
                print((odd[i][1])+1,(odd[i+1][1])+1)
        if(len(even)!=0):
            for i in range(0,len(even),2):
                print((even[i][1])+1,(even[i+1][1])+1)

    elif(flag==2):
        a=min(odd)
        b=min(even)
        odd.remove(a)
        even.remove(b)
        #print(len(even),len(odd))
        #print(even)
        #print(odd)
        if(len(odd)!=0):
            for i in range(0,len(odd),2):
                print((odd[i][1])+1,(odd[i+1][1])+1)
        if(len(even)!=0):
            for i in range(0,len(even),2):
                print((even[i][1])+1,(even[i+1][1])+1)