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

#define ll long long
#define ii pair<int,int>
#define f first
#define s second
#define pb push_back

bool fsort(ii a, ii b){
    if (a.first != b.first)
        return a.first > b.first;
    return a.second < b.second;
}

struct fsort2{
    bool operator()(const ii &a, const ii &b) const{
        return a.first-a.second < b.first-b.second;
    }
};

int main (){
	int q, n, a, f, cntmy;
	scanf("%d", &q);
	while(q--){
		map<int,ii> M;
		vector<ii> V;

		int cntmy = 0;
		scanf("%d", &n);
		for (int i = 0; i < n; i++){
			scanf("%d%d", &a, &f);
			M[a].first++;
			M[a].second+=(int)(!f);
			cntmy += (int)(!f);
		}
        for (map<int,ii>::iterator a = M.begin(); a != M.end(); a++){
            V.pb(ii(a->second.first, a->second.second));
        }

		sort(V.begin(), V.end(), fsort);
		priority_queue<ii, vector<ii>, fsort2> PQ;

		ll cnt = 0, lst = V[0].first+1, my = 0;
		int k = 0;
		for (int i = 0; i < (int)V.size(); i++){
			lst = max(min(lst-1, (ll)V[i].first), 0ll);
			while (k < V.size() && V[k].first >= lst)
                PQ.push(V[k++]);
			cnt += lst;
			int arg = min(PQ.top().second, max(0, PQ.top().second - ((int)lst - (PQ.top().first-PQ.top().second))));
			my += arg;
			PQ.pop();
		}
		cout << cnt << " " << cnt - (cntmy-my) << "\n";
	}
}


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

#define ll long long
#define ii pair<int,int>
#define f first
#define s second
#define pb push_back

bool fsort(ii a, ii b){
    if (a.first != b.first)
        return a.first > b.first;
    return a.second < b.second;
}

struct fsort2{
    bool operator()(const ii &a, const ii &b) const{
        return a.first-a.second < b.first-b.second;
    }
};

int main (){
	int q, n, a, f, cntmy;
	scanf("%d", &q);
	while(q--){
		map<int,ii> M;
		vector<ii> V;

		scanf("%d", &n);
		for (int i = 0; i < n; i++){
			scanf("%d%d", &a, &f);
			M[a].first++;
			M[a].second+=(int)(!f);
		}
        for (map<int,ii>::iterator a = M.begin(); a != M.end(); a++){
            V.pb(ii(a->second.first, a->second.second));
        }

		sort(V.begin(), V.end(), fsort);
		priority_queue<ii, vector<ii>, fsort2> PQ;

		ll cnt = 0, lst = V[0].first+1, give = 0;
		int k = 0;
		for (int i = 0; i < (int)V.size(); i++){
			lst = max(min(lst-1, (ll)V[i].first), 0ll);
			while (k < V.size() && V[k].first >= lst)
                PQ.push(V[k++]);
			cnt += lst;
			give += min((int)lst, PQ.top().first-PQ.top().second);
			PQ.pop();
		}
		cout << cnt << " " << give << "\n";
	}
}


/*
ID: fedorts1
LANG: C++
TASK: concom
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <list>

#pragma GCC optimize("O3")

#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)

using namespace std;
ll sqr(ll a) { return a * a; };
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
unordered_map<ll, pll> ump;
vector<pll> vc;
priority_queue<ll> pq;
bool cmp(pll a, pll b) { return a.first == b.first ? a.second > b.second : a.first > b.first; }

int main()
{
    //freopen("concom.in", "r", stdin), freopen("concom.out", "w", stdout);
    fast_io;
    ll n, q, i, j, a, b, nm, ans, rzm;
    cin >> q;
    for (i = 0; i < q; i++)
    {
        cin >> n;
        ans = rzm = 0;
        for (j = 0; j < n; j++)
        {
            cin >> a >> b;
            if (ump.find(a) == ump.end()) ump.insert({a, {0, 0}});
            ump[a].first++;
            ump[a].second += b;
        }
        for (auto f = ump.begin(); f != ump.end(); f++) vc.pb({f->second.first, f->second.second});
        sort(all(vc), cmp);
        nm = vc[0].first;
        for (j = 0; j < vc.size(); )
        {
            if (vc[j].first == nm)
            {
                pq.push(vc[j].second);
                j++;
            }
            else
            {
                if (!pq.empty())
                {
                    ans += min(nm, pq.top());
                    rzm += nm;
                    pq.pop();
                }
                nm--;
            }
        }
        while (nm > 0 && !pq.empty())
        {
            ans += min(nm, pq.top());
            rzm += nm;
            nm--;
            pq.pop();
        }
        cout << rzm << ' ' << ans << '\n';
        ump.clear();
        while (!pq.empty()) pq.pop();
        vc.clear();
    }
    return 0;
}


/*
ID: fedorts1
LANG: C++
TASK: concom
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <list>

#pragma GCC optimize("O3")

#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)

using namespace std;
ll sqr(ll a) { return a * a; };
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
unordered_map<ll, pll> ump;
vector<pll> vc;
priority_queue<ll> pq;
bool cmp(pll a, pll b) { return a.first == b.first ? a.second > b.second : a.first > b.first; }

int main()
{
    //freopen("concom.in", "r", stdin), freopen("concom.out", "w", stdout);
    fast_io;
    ll n, q, i, j, a, b, nm, ans, rzm;
    cin >> q;
    for (i = 0; i < q; i++)
    {
        cin >> n;
        ans = rzm = 0;
        for (j = 0; j < n; j++)
        {
            cin >> a >> b;
            if (ump.find(a) == ump.end()) ump.insert({a, {0, 0}});
            ump[a].first++;
            ump[a].second += b;
        }
        for (auto f = ump.begin(); f != ump.end(); f++) vc.pb({f->second.first, f->second.second});
        sort(all(vc), cmp);
        nm = vc[0].first;
        for (j = 0; nm > 0 && j < vc.size(); )
        {
            if (vc[j].first == nm)
            {
                pq.push(vc[j].second);
                j++;
            }
            else
            {
                if (!pq.empty())
                {
                    ans += pq.top();
                    rzm += nm;
                    pq.pop();
                }
                nm--;
            }
        }
        while (nm > 0 && !pq.empty())
        {
            ans += min(nm, pq.top());
            rzm += nm;
            nm--;
            pq.pop();
        }
        cout << rzm << ' ' << ans << '\n';
        ump.clear();
        while (!pq.empty()) pq.pop();
        vc.clear();
    }
    return 0;
}


/*
ID: fedorts1
LANG: C++
TASK: concom
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <list>

#pragma GCC optimize("O3")

#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)

using namespace std;
ll sqr(ll a) { return a * a; };
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
unordered_map<ll, pll> ump;
vector<pll> vc;
priority_queue<ll> pq;
bool cmp(pll a, pll b) { return a.first == b.first ? a.second > b.second : a.first > b.first; }

int main()
{
    //freopen("concom.in", "r", stdin), freopen("concom.out", "w", stdout);
    fast_io;
    ll n, q, i, j, a, b, nm, ans, rzm;
    cin >> q;
    for (i = 0; i < q; i++)
    {
        cin >> n;
        ans = rzm = 0;
        for (j = 0; j < n; j++)
        {
            cin >> a >> b;
            if (ump.find(a) == ump.end()) ump.insert({a, {0, 0}});
            ump[a].first++;
            ump[a].second += b;
        }
        for (auto f = ump.begin(); f != ump.end(); f++) vc.pb({f->second.first, f->second.second});
        sort(all(vc), cmp);
        nm = vc[0].first;
        for (j = 0; j < vc.size(); )
        {
            if (vc[j].first == nm)
            {
                pq.push(vc[j].second);
                j++;
            }
            else if (!pq.empty())
            {
                ans += min(nm, pq.top());
                rzm += nm;
                pq.pop();
                nm--;
            }
        }
        while (nm > 0 && !pq.empty())
        {
            ans += min(nm, pq.top());
            rzm += nm;
            nm--;
            pq.pop();
        }
        cout << rzm << ' ' << ans << '\n';
        ump.clear();
        while (!pq.empty()) pq.pop();
        vc.clear();
    }
    return 0;
}


/*
ID: fedorts1
LANG: C++
TASK: concom
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <list>

#pragma GCC optimize("O3")

#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)

using namespace std;
ll sqr(ll a) { return a * a; };
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
unordered_map<ll, pll> ump;
vector<pll> vc;
priority_queue<ll> pq;
bool cmp(pll a, pll b) { return a.first == b.first ? a.second > b.second : a.first > b.first; }

int main()
{
    //freopen("concom.in", "r", stdin), freopen("concom.out", "w", stdout);
    fast_io;
    ll n, q, i, j, a, b, nm, ans, rzm;
    cin >> q;
    for (i = 0; i < q; i++)
    {
        cin >> n;
        ans = rzm = 0;
        for (j = 0; j < n; j++)
        {
            cin >> a >> b;
            if (ump.find(a) == ump.end()) ump.insert({a, {0, 0}});
            ump[a].first++;
            ump[a].second += b;
        }
        for (auto f = ump.begin(); f != ump.end(); f++) vc.pb({f->second.first, f->second.second});
        sort(all(vc), cmp);
        nm = vc[0].first;
        for (j = 0; j < vc.size(); )
        {
            if (vc[j].first == nm)
            {
                pq.push(vc[j].second);
                j++;
            }
            else if (vc[j].first < nm && !pq.empty())
            {
                ans += min(nm, pq.top());
                rzm += nm;
                pq.pop();
                nm--;
            }
        }
        while (nm > 0 && !pq.empty())
        {
            ans += min(nm, pq.top());
            rzm += nm;
            nm--;
            pq.pop();
        }
        cout << rzm << ' ' << ans << '\n';
        ump.clear();
        while (!pq.empty()) pq.pop();
        vc.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct node
{
	long long int p;
	long long int q;
	long long int r;
};
bool ram(struct node x,struct node y)
{
	if(x.q==y.q)
	return x.r>y.r;
	return x.q>y.q;
}
int main() {
	// your code goes here
	long long int x,p,q,r,s,ans,i,y,l,ram1,k,n,j;
	struct node b[300000],a[300000];
	map<int,int>m;
	map<int,int>m1;
	map<int,int>::iterator it;
	cin>>x;
	while(x--)
	{
		ans=0;
	  	cin>>y;
	  	for(i=0;i<y;i++)
	  	cin>>a[i].p>>a[i].q;
	  	//sort(a,a+y);
	  	for(i=0;i<y;i++)
	  	{
	    	m[a[i].p]=m[a[i].p]+1;
	     	if(a[i].q==1)
	     	m1[a[i].p]=m1[a[i].p]+1;
	    	else
	     	m1[a[i].p]=m1[a[i].p];
	  	}
	  	l=0;
	  	for(it=m.begin();it!=m.end();++it)
	  	{
	  		b[l].p=it->first;
	  		b[l].q=it->second;
	  		//cout<<it->first<<it->second<<endl;
	  	  l++;
	  	}

	  	l=0;
	  	for(it=m1.begin();it!=m1.end();++it)
	  	{

	  		b[l].r=it->second;
	  		//cout<<it->first<<it->second<<endl;
	  	  l++;
	  	}
	  		sort(b,b+l,ram);
	  /*	for(i=0;i<l;i++)
	  	{
	  		cout<<b[i].p<<" "<<b[i].q<<" "<<b[i].r<<endl;
	  	}*/
	  	ans=b[0].q;
	  	ram1=b[0].r;
	  	k=ans;
        for(i=1;i<l;i++)
        {
        	k--;
        	if(k==0)
        	break;
        	n=-1;
        	p=-1;
        	for(j=1;j<l;j++)
        	{
        		if(k<=b[j].q && n<b[j].r)
        		{
                   n=b[j].r;
                   p=j;
        		}
        	}
        	if(p!=-1){
        	ans=ans+min(k,b[p].q);
        	ram1=ram1+min(n,k);
        	b[p].q=0;
        	b[p].r=0;
        	}

        }
	  	cout<<ans<<" "<<ram1<<endl;

	  	m.clear();
	  	m1.clear();

	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define s second
#define f first
#define pb push_back
#define mk make_pair
using namespace std;
int main()
{
    unordered_map<ll,ll> mp;
    set<pair<ll,ll>> s,small;
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        ll x=it->f;
        ll y=it->s;
        s.insert({y,x});
    }
    ll cnt=0;
    for(auto it=s.rbegin();it!=s.rend();it++)
    {
        small.insert(*it);
        cnt++;
        if(cnt==4)
        break;
    }
    ll t;
    cin>>t;
    while(t--)
    {
        char ch;
        ll a,b;
        cin>>ch>>a;
        b=mp[a];
        auto it=small.find({b,a});
        if(ch=='+')
        b++;
        else
        b--;
        mp[a]=b;
        small.erase(it);
        small.insert({b,a});
        if(small.size()>4)
        {
            small.erase(small.begin());
        }
        auto it1=small.rbegin();
        ll x1=0,x2=0,x3=0,y1=0,y2=0,y3=0;
        x1=it1->f;
        y1=it1->s;
        it1++;
        if(it1!=small.rend())
        {
            x2=it1->f;
            y2=it1->s;
        }
        it1++;
        if(it1!=small.rend())
        {
            x3=it1->f;
            y3=it1->s;
        }
        ll f=0;
        if(x1>0&&x2==0)
        {
            if(x1>=8)
            {
                f=1;
            }
        }
        if(x1>=1&&x2>=1&&x3==0)
        {
            if((x1>=4&&x2>=4)||(x1>=6&&x2>=2)||(x1>=8))
            {
                f=1;
            }
        }
        if(x1>=1&&x2>=1&&x3>=1 )
        {
            if((x1>=4&&x2 >= 2&&x3>=2)||(x1>=6&&x2>=2)||(x1>=4&&x2>=4)||(x1>=8))
            {
                f=1;
            }
        }
        if(f==1)
        {
            cout<<"YES"<<endl;
        }
        else
        cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long int
#define s second
#define f first
#define pb push_back
#define mk make_pair
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
    map<int,int> mp;
    set<pair<int,int>> s;
    int n;
    cin>>n;
    int x;
    for(int i=1;i<=1e5;i++)
	mp[i] = 0;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        mp[x]++;
    }
    for(int i=1;i<=1e5;i++)
    {
        s.insert(mk(mp[i],i));
    }
    int t;
    cin>>t;
    while(t--)
    {
        char c;
		cin >> c; int x; cin >> x;
		if (c == '+')
		{
			auto it = s.find(mk(mp[x], x));
			s.erase(it);
			mp[x]++;
			s.insert(mk(mp[x], x));

		}
		else
		{
			auto it = s.find(mk(mp[x], x));
			s.erase(it);
			mp[x]--;
			s.insert(mk(mp[x], x));
		}
        auto it1=s.rbegin();
        int x1=it1->f;
        int y1=it1->s;
        int x2=0,x3=0,y2=0,y3=0;
        it1++;
        if(it1!=s.rend())
        {
            x2=it1->f;
            y2=it1->s;
        }
        it1++;
        if(it1!=s.rend())
        {
            x3=it1->f;
            y3=it1->s;
        }
        //cout<<x1<<" "<<x2<<endl;
        if (x1 >= 4)
		x1=x1-4;
		else
		{
			cout << "NO" << endl; continue;
		}
		int cnt = 0;
		if (x1 >= 2 && x1 < 4)
			cnt++;
		else if (x1 >= 4)
			cnt += 2;
		if (x2 >= 2 && x2 < 4)
			cnt++;
		else if (x2 >= 4)
			cnt += 2;
		if (x3 >= 2 && x3 < 4)
			cnt++;
		else if (x3 >= 4)
			cnt += 2;

		if (cnt >= 2)
			cout <<"YES" << endl;
		else
			cout <<"NO" << endl;
    }
}


#include <bits/stdc++.h>
#define ll long long int
#define s second
#define f first
#define pb push_back
#define mk make_pair
using namespace std;
int main()
{
    unordered_map<ll,ll> mp;
    set<pair<ll,ll>> s;
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        ll x=it->f;
        ll y=it->s;
        s.insert({y,x});
    }
    ll t;
    cin>>t;
    while(t--)
    {
        char ch;
        ll a,b;
        cin>>ch>>a;
        b=mp[a];
        auto it=s.find({b,a});
        if(ch=='+')
        b++;
        else
        b--;
        mp[a]=b;
        s.erase(it);
        s.insert({b,a});
        auto it1=s.rbegin();
        ll x1=it1->f;
        ll y1=it1->s;
        it1++;
        ll x2=it1->f;
        ll y2=it1->s;
        it1++;
        ll x3=it1->f;
        ll y3=it1->s;
        //cout<<x1<<" "<<x2<<endl;
        if(x1>=4)
        {
            x1=x1-4;
            if(x1>=2&&x2>=2)
            {
                cout<<"YES"<<endl;
            }
            else if(x1>=4)
            {
                cout<<"YES"<<endl;
            }
            else if(x2>=4)
            {
                cout<<"YES"<<endl;
            }
            else
            cout<<"NO"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long int
#define s second
#define f first
#define pb push_back
#define mk make_pair
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
    map<int,int> mp;
    set<pair<int,int>> s;
    int n;
    cin>>n;
    int x;
    for(int i=1;i<=1e5;i++)
	mp[i] = 0;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        mp[x]++;
    }
    for(int i=1;i<=1e5;i++)
    {
        s.insert(mk(mp[i],i));
    }
    int t;
    cin>>t;
    while(t--)
    {
        char c;
		cin >> c; int x; cin >> x;
		if (c == '+')
		{
			auto it = s.find(mk(mp[x], x));
			s.erase(it);
			mp[x]++;
			s.insert(mk(mp[x], x));

		}
		else
		{
			auto it = s.find(mk(mp[x], x));
			s.erase(it);
			mp[x]--;
			s.insert(mk(mp[x], x));
		}
        auto it1=s.rbegin();
        int x1=it1->f;
        int y1=it1->s;
        int x2=0,x3=0,y2=0,y3=0;
        it1++;
        if(it1!=s.rend())
        {
            x2=it1->f;
            y2=it1->s;
        }
        it1++;
        if(it1!=s.rend())
        {
            x3=it1->f;
            y3=it1->s;
        }
        //cout<<x1<<" "<<x2<<endl;
        if(x1>=4)
        {
            x1=x1-4;
            if(x1>=2&&x2>=2)
            {
                cout<<"YES"<<endl;
            }
            else if(x1>=4)
            {
                cout<<"YES"<<endl;
            }
            else if(x2>=4)
            {
                cout<<"YES"<<endl;
            }
            else
            cout<<"NO"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FILE freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
typedef long long ll ;
typedef long double ld ;
const double PI=acos(-1);
int main(){
    //FAST_IO;
    //FILE;
    int t;
    cin>>t;
    int a[t+1];
    int mini=INT_MAX,maxi=INT_MIN;
    for(int i=0;i<t;i++){
        cin>>a[i];
        mini=min(a[i],mini);
        maxi=max(a[i],maxi);
    }
    int two=0,four=0,six=0,eight=0;
    int planks[1000007]={0};
    for(int i=0;i<t;i++){
        planks[a[i]]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8)
            six++;
        else if(planks[i]>=8)
            eight++;
    }
    int m;
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                six++;
                four--;
            }
            else if(planks[n]==7){
                six--;
                eight++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                six--;
                four++;
            }
            else if(planks[n]==8){
                eight--;
                six++;
            }
            planks[n]--;
        }
        if(two>=4){
            yes;
        }else if(four>=2 || (two>=2 && four>0)){
            yes;
        }else if(six>=2){
            yes;
        }else if((two>0 && six>0) || (six>0 && four>0)){
            yes;
        }else if(eight>0){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FILE freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
typedef long long ll ;
typedef long double ld ;
const double PI=acos(-1);
int main(){
    //FAST_IO;
    //FILE;
    int t;
    cin>>t;
    int a[t+1];
    int mini=INT_MAX,maxi=INT_MIN;
    for(int i=0;i<t;i++){
        cin>>a[i];
        mini=min(a[i],mini);
        maxi=max(a[i],maxi);
    }
    int two=0,four=0,six=0,eight=0;
    int planks[maxi+2]={0};
    for(int i=0;i<t;i++){
        planks[a[i]]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8)
            six++;
        else if(planks[i]>=8)
            eight++;
    }
    int m;
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                six++;
                four--;
            }
            else if(planks[n]==7){
                six--;
                eight++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                six--;
                four++;
            }
            else if(planks[n]==8){
                eight--;
                six++;
            }
            planks[n]--;
        }
        cout<<two<<" "<<four<<" "<<six<<" "<<eight<<nl;
        if(two>=4){
            yes;
        }else if(four>=2 || (two>=2 && four>0)){
            yes;
        }else if(six>=2){
            yes;
        }else if((two>0 && six>0) || (six>0 && four>0)){
            yes;
        }else if(eight>0){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FILE freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
typedef long long ll ;
typedef long double ld ;
const double PI=acos(-1);
int main(){
    FAST_IO;
    int t,x,m,mini=INT_MAX,maxi=INT_MIN;
    int two=0,four=0,six=0,eight=0;
    map <int,int> planks;
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>x;
        mini=min(x,mini);
        maxi=max(x,maxi);
        planks[x]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8){
            two++;
            four++;
        }
        else if(planks[i]>=8)
            four+=2;
    }
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                two++;
            }
            else if(planks[n]==7){
                four++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                two--;
            }
            else if(planks[n]==8){
                four--;
            }
            planks[n]--;
        }
        if(two>=4){
            yes;
        }else if(four>=2 || (two>=2 && four>0)){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FILE freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
typedef long long ll ;
typedef long double ld ;
const double PI=acos(-1);
int main(){
    FAST_IO;
    //FILE;
    int t;
    cin>>t;
    int a[t+1];
    int mini=INT_MAX,maxi=INT_MIN;
    for(int i=0;i<t;i++){
        cin>>a[i];
        mini=min(a[i],mini);
        maxi=max(a[i],maxi);
    }
    int two=0,four=0,six=0,eight=0;
    int planks[1000007]={0};
    for(int i=0;i<t;i++){
        planks[a[i]]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8)
            six++;
        else if(planks[i]>=8)
            eight++;
    }
    int m;
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                six++;
                four--;
            }
            else if(planks[n]==7){
                six--;
                eight++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                six--;
                four++;
            }
            else if(planks[n]==8){
                eight--;
                six++;
            }
            planks[n]--;
        }
        if(four>=2 || (two>=2 && four>0)){
            yes;
        }else if(six>=2){
            yes;
        }else if((two>0 && six>0) || (six>0 && four>0)){
            yes;
        }else if(eight>0){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
int main(){
    FAST_IO;
    int t,x,m,mini=INT_MAX,maxi=INT_MIN;
    int two=0,four=0;
    int planks[100005]={0};
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>x;
        mini=min(x,mini);
        maxi=max(x,maxi);
        planks[x]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8){
            two++;
            four++;
        }
        else if(planks[i]>=8)
            four+=2;
    }
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                two++;
            }
            else if(planks[n]==7){
                four++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                two--;
            }
            else if(planks[n]==8){
                four--;
            }
            planks[n]--;
        }
        if(four>=2 || (two>=2 && four>0)){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FILE freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
typedef long long ll ;
typedef long double ld ;
const double PI=acos(-1);
int main(){
    //FAST_IO;
    //FILE;
    int t;
    cin>>t;
    int a[t+1];
    int mini=INT_MAX,maxi=INT_MIN;
    for(int i=0;i<t;i++){
        cin>>a[i];
        mini=min(a[i],mini);
        maxi=max(a[i],maxi);
    }
    int two=0,four=0,six=0,eight=0;
    int planks[maxi+2]={0};
    for(int i=0;i<t;i++){
        planks[a[i]]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8)
            six++;
        else if(planks[i]>=8)
            eight++;
    }
    int m;
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                six++;
                four--;
            }
            else if(planks[n]==7){
                six--;
                eight++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                six--;
                four++;
            }
            else if(planks[n]==8){
                eight--;
                six++;
            }
            planks[n]--;
        }
        if(two>=4){
            yes;
        }else if(four>=2 || (two>=2 && four>0)){
            yes;
        }else if(six>=2){
            yes;
        }else if((two>0 && six>0) || (six>0 && four>0)){
            yes;
        }else if(eight>0){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
int main(){
    FAST_IO;
    int t,x,m,mini=INT_MAX,maxi=INT_MIN;
    int two=0,four=0;
    int planks[100005]={0};
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>x;
        mini=min(x,mini);
        maxi=max(x,maxi);
        planks[x]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8){
            two++;
            four++;
        }
        else if(planks[i]>=8)
            four+=2;
    }
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                two++;
            }
            else if(planks[n]==7){
                four++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                two--;
            }
            else if(planks[n]==8){
                four--;
            }
            planks[n]--;
        }else if(four>=2 || (two>=2 && four>0)){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FILE freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
typedef long long ll ;
typedef long double ld ;
const double PI=acos(-1);
int main(){
    //FAST_IO;
    //FILE;
    int t;
    int planks[100007]={0};
    cin>>t;
    int x;
    int two=0,four=0,six=0,eight=0;
    int mini=INT_MAX,maxi=INT_MIN;
    for(int i=0;i<t;i++){
        cin>>x;
        mini=min(x,mini);
        maxi=max(x,maxi);
        planks[x]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8)
            six++;
        else if(planks[i]>=8)
            eight++;
    }
    int m;
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                six++;
                four--;
            }
            else if(planks[n]==7){
                six--;
                eight++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                six--;
                four++;
            }
            else if(planks[n]==8){
                eight--;
                six++;
            }
            planks[n]--;
        }
        if(two>=4){
            yes;
        }else if(four>=2 || (two>=2 && four)){
            yes;
        }else if(six>=2){
            yes;
        }else if((two && six) || (six && four)){
            yes;
        }else if(eight){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FILE freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
typedef long long ll ;
typedef long double ld ;
const double PI=acos(-1);
int main(){
    FAST_IO;
    int t,x,m,mini=INT_MAX,maxi=INT_MIN;
    int two=0,four=0,six=0,eight=0;
    int planks[100007]={0};
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>x;
        mini=min(x,mini);
        maxi=max(x,maxi);
        planks[x]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8){
            two++;
            four++;
        }
        else if(planks[i]>=8)
            four+=2;
    }
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                two++;
            }
            else if(planks[n]==7){
                four++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                two--;
            }
            else if(planks[n]==8){
                four--;
            }
            planks[n]--;
        }
        if(two>=4){
            yes;
        }else if(four>=2 || (two>=2 && four>0)){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FILE freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
typedef long long ll ;
typedef long double ld ;
const double PI=acos(-1);
int main(){
    //FAST_IO;
    //FILE;
    int t;
    int planks[100007]={0};
    cin>>t;
    int x;
    int two=0,four=0,six=0,eight=0;
    int mini=INT_MAX,maxi=INT_MIN;
    for(int i=0;i<t;i++){
        cin>>x;
        mini=min(x,mini);
        maxi=max(x,maxi);
        planks[x]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8)
            six++;
        else if(planks[i]>=8)
            eight++;
    }
    int m;
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                six++;
                four--;
            }
            else if(planks[n]==7){
                six--;
                eight++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                six--;
                four++;
            }
            else if(planks[n]==8){
                eight--;
                six++;
            }
            planks[n]--;
        }
        cout<<two<<" "<<four<<" "<<six<<" "<<eight<<nl;
        if(two>=4){
            yes;
        }else if(four>=2 || (two>=2 && four)){
            yes;
        }else if(six>=2){
            yes;
        }else if((two && six) || (six && four)){
            yes;
        }else if(eight){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FILE freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
typedef long long ll ;
typedef long double ld ;
const double PI=acos(-1);
int main(){
    //FAST_IO;
    int t,x,m,mini=INT_MAX,maxi=INT_MIN;
    int two=0,four=0,six=0,eight=0;
    int planks[100007]={0};
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>x;
        mini=min(x,mini);
        maxi=max(x,maxi);
        planks[x]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8)
            six++;
        else if(planks[i]>=8)
            eight++;
    }
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                six++;
                four--;
            }
            else if(planks[n]==7){
                six--;
                eight++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                six--;
                four++;
            }
            else if(planks[n]==8){
                eight--;
                six++;
            }
            planks[n]--;
        }
        if(two>=4){
            yes;
        }else if(four>=2 || (two>=2 && four>0)){
            yes;
        }else if(six>=2){
            yes;
        }else if((two>0 && six>0) || (six>0 && four>0)){
            yes;
        }else if(eight>0){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FILE freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
typedef long long ll ;
typedef long double ld ;
const double PI=acos(-1);
int main(){
    //FAST_IO;
    //FILE;
    int t;
    cin>>t;
    int a[t+1];
    int mini=INT_MAX,maxi=INT_MIN;
    for(int i=0;i<t;i++){
        cin>>a[i];
        mini=min(a[i],mini);
        maxi=max(a[i],maxi);
    }
    int two=0,four=0,six=0,eight=0;
    int planks[100007]={0};
    for(int i=0;i<t;i++){
        planks[a[i]]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8)
            six++;
        else if(planks[i]>=8)
            eight++;
    }
    int m;
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                six++;
                four--;
            }
            else if(planks[n]==7){
                six--;
                eight++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                six--;
                four++;
            }
            else if(planks[n]==8){
                eight--;
                six++;
            }
            planks[n]--;
        }
        if(two>=4){
            yes;
        }else if(four>=2 || (two>=2 && four>0)){
            yes;
        }else if(six>=2){
            yes;
        }else if((two>0 && six>0) || (six>0 && four>0)){
            yes;
        }else if(eight>0){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FILE freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
typedef long long ll ;
typedef long double ld ;
const double PI=acos(-1);
int main(){
    //FAST_IO;
    //FILE;
    int t;
    cin>>t;
    int a[t+1];
    int mini=INT_MAX,maxi=INT_MIN;
    for(int i=0;i<t;i++){
        cin>>a[i];
        mini=min(a[i],mini);
        maxi=max(a[i],maxi);
    }
    int two=0,four=0,six=0,eight=0;
    int planks[100007]={0};
    for(int i=0;i<t;i++){
        planks[a[i]]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8)
            six++;
        else if(planks[i]>=8)
            eight++;
    }
    int m;
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                six++;
                four--;
            }
            else if(planks[n]==7){
                six--;
                eight++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                six--;
                four++;
            }
            else if(planks[n]==8){
                eight--;
                six++;
            }
            planks[n]--;
        }
        if(two>=4){
            yes;
        }else if(four>=2 || (two>=2 && four>0)){
            yes;
        }else if((two>0 && six>0)){
            yes;
        }else if(eight>0){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FILE freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
const char nl = '\n';
typedef long long ll ;
typedef long double ld ;
const double PI=acos(-1);
int main(){
    FAST_IO;
    //FILE;
    int t;
    cin>>t;
    int a[t+1];
    int mini=INT_MAX,maxi=INT_MIN;
    for(int i=0;i<t;i++){
        cin>>a[i];
        mini=min(a[i],mini);
        maxi=max(a[i],maxi);
    }
    int two=0,four=0,six=0,eight=0;
    int planks[1000007]={0};
    for(int i=0;i<t;i++){
        planks[a[i]]++;
    }
    for(int i=mini;i<=maxi;i++){
        if(planks[i]>=2 && planks[i]<4)
            two++;
        else if(planks[i]>=4 && planks[i]<6)
            four++;
        else if(planks[i]>=6 && planks[i]<8)
            six++;
        else if(planks[i]>=8)
            eight++;
    }
    int m;
    cin>>m;
    while(m--){
        char c;
        int n;
        cin>>c>>n;
        if(c=='+'){
            if(planks[n]==1){
                two++;
            }
            else if(planks[n]==3){
                two--;
                four++;
            }
            else if(planks[n]==5){
                six++;
                four--;
            }
            else if(planks[n]==7){
                six--;
                eight++;
            }
            planks[n]++;
        }else{
            if(planks[n]==2)
                two--;
            else if(planks[n]==4){
                four--;
                two++;
            }
            else if(planks[n]==6){
                six--;
                four++;
            }
            else if(planks[n]==8){
                eight--;
                six++;
            }
            planks[n]--;
        }
        if(two>=4){
            yes;
        }else if(four>=2 || (two>=2 && four>0)){
            yes;
        }else if(six>=2){
            yes;
        }else if((two>0 && six>0) || (six>0 && four>0)){
            yes;
        }else if(eight>0){
            yes;
        }else{
            no;
        }
    }
    return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> > setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

ll bit[100005];

void add(ll pos, ll val) {
        for(ll k = pos; k <= 1e5; k += (k & -k)) bit[k] += val;
}

ll sum(ll pos) {
        ll s = 0;
        for(ll k = pos; k > 0; k -= (k & -k)) s += bit[k];
        return s;
}

ll qry(ll pos) {
        return sum(pos) - sum(pos - 1);
}

void solve() {
        ll n, q;
        cin >> n;
        multiset<pair<ll, ll>> s;
        for(int i = 0, x; i < n; ++i) {
                cin >> x;
                add(x, 1);
        }
        cin >> q;
        for(int i = 1; i <= 100000; ++i)
                if(qry(i) > 0)
                        s.insert({qry(i), i});

        while(s.size() > 3) s.erase(s.begin());
        while(q--) {
                char ch;
                ll p;
                cin >> ch >> p;
                if(ch == '+') {
                        ll v = qry(p);
                        add(p, 1);
                        auto it = s.find({v, p});
                        if(it == s.end()) {
                                s.insert({v + 1, p});
                        }
                        else {
                                s.erase(it);
                                s.insert({v + 1, p});
                        }
                }
                else {
                        ll v = qry(p);
                        add(p, -1);
                        auto it = s.find({v, p});
                        if(it == s.end()) {
                                if(v > 1) s.insert({v - 1, p});
                        }
                        else {
                                s.erase(it);
                                if(v > 1) s.insert({v - 1, p});
                        }
                }

                while(s.size() > 3) s.erase(s.begin());
                auto it = s.end();

                ll a, b, c;
                a = b = c = 0;

                if(s.size() >= 1) {
                        --it;
                        a = it->first;
                }
                if(s.size() >= 2) {
                        --it;
                        b = it->first;
                }
                if(s.size() >= 3) {
                        --it;
                        c = it->first;
                }

                bool ok = 0;

                if(a >= 4 && b >= 4) ok = 1;
                if(a >= 6 && b >= 2) ok = 1;
                if(a >= 4 && b >= 2 && c >= 2) ok = 1;

                if(ok) cout << "YES\n";
                else cout << "NO\n";
        }
}

int main() {
        ios::sync_with_stdio(0);
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> > setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

ll bit[200005];

void add(ll pos, ll val) {
        for(ll k = pos; k <= 1e5; k += (k & -k)) bit[k] += val;
}

ll sum(ll pos) {
        ll s = 0;
        for(ll k = pos; k > 0; k -= (k & -k)) s += bit[k];
        return s;
}

ll qry(ll pos) {
        return sum(pos) - sum(pos - 1);
}

void solve() {
        ll n, q;
        cin >> n;
        multiset<pair<ll, ll>> s;
        for(int i = 0, x; i < n; ++i) {
                cin >> x;
                add(x, 1);
        }
        cin >> q;
        for(int i = 1; i <= n; ++i)
                if(qry(i) > 0)
                        s.insert({qry(i), i});

        while(s.size() > 3) s.erase(s.begin());
        while(q--) {
                char ch;
                ll p;
                cin >> ch >> p;
                if(ch == '+') {
                        ll v = qry(p);
                        add(p, 1);
                        auto it = s.find({v, p});
                        if(it == s.end()) {
                                s.insert({v + 1, p});
                        }
                        else {
                                s.erase(it);
                                s.insert({v + 1, p});
                        }
                }
                else {
                        ll v = qry(p);
                        add(p, -1);
                        auto it = s.find({v, p});
                        if(it == s.end()) {
                                if(v > 1) s.insert({v - 1, p});
                        }
                        else {
                                s.erase(it);
                                if(v > 1) s.insert({v - 1, p});
                        }
                }

                while(s.size() > 3) s.erase(s.begin());
                auto it = s.end();

                ll a, b, c;
                a = b = c = 0;

                if(s.size() >= 1) {
                        --it;
                        a = it->first;
                }
                if(s.size() >= 2) {
                        --it;
                        b = it->first;
                }
                if(s.size() >= 3) {
                        --it;
                        a = it->first;
                }

                bool ok = 0;

                if(a >= 8) ok = 1;
                if(a >= 4 && b >= 4) ok = 1;
                if(a >= 6 && b >= 2) ok = 1;
                if(a >= 4 && b >= 2 && c >= 2) ok = 1;

                if(ok) cout << "YES\n";
                else cout << "NO\n";
        }
}

int main() {
        ios::sync_with_stdio(0);
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> > setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

void solve() {
        ll n, q;
        cin >> n;
        vec a(n);
        setpi s;
        mseti vals;
        for(auto &it : a) {
                cin >> it;
                auto ite = s.lower_bound({it, 0});
                if(ite == s.end()) {
                        s.insert({it, 1});
                }
                else {
                        ll x = ite->first;
                        ll y = ite->second;
                        s.erase(ite);
                        ++y;
                        s.insert({x, y});
                }
        }

        for(auto &it : s) {
                vals.insert(it.second);
        }

        cin >> q;
        while(q--) {
                char ch;
                ll p;
                cin >> ch >> p;
                if(ch == '-') {
                        auto it = s.lower_bound({p, 0});
                        ll x = it->first;
                        ll y = it->second;
                        s.erase(it);
                        vals.erase(vals.find(y));
                        --y;
                        if(y > 0) s.insert({x, y}), vals.insert(y);
                }
                else {
                        auto it = s.lower_bound({p, 0});
                        ll x = it->first;
                        ll y = it->second;
                        s.erase(it);
                        vals.erase(vals.find(y));
                        ++y;
                        s.insert({x, y});
                        vals.insert(y);
                }
                bool ok = 0;
                if(vals.size() >= 1) {
                        auto it = vals.end();
                        --it;
                        ll val = *it;
                        if(val >= 8) ok = 1;
                }
                if(vals.size() >= 2 && !ok) {
                        auto it = vals.end();
                        --it;
                        ll val1 = *it;
                        --it;
                        ll val2 = *it;
                        if(val1 >= 4 && val2 >= 4) ok = 1;
                        if(val1 >= 6 && val2 >= 2) ok = 1;
                }
                if(vals.size() >= 3 && !ok) {
                        auto it = vals.end();
                        --it;
                        ll val1 = *it;
                        --it;
                        ll val2 = *it;
                        --it;
                        ll val3 = *it;
                        if(val1 >= 4 && val2 >= 2 && val3 >= 2) ok = 1;
                }
                if(ok) {
                        cout << "YES\n";
                }
                else {
                        cout << "NO\n";
                }
        }
}

int main() {
        ios::sync_with_stdio(0);
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> >      setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

ll cnt[100005];
multiset<ll> vals;

void solve() {
        ll n, q;
        cin >> n;
        for(ll i = 1, x; i <= n; ++i) {
                cin >> x;
                ++cnt[x];
        }
        for(int i = 1; i <= n; ++i)
                if(cnt[i] > 0) vals.insert(cnt[i]);
        cin >> q;
        while(q--) {
                char ch;
                ll x;
                cin >> ch >> x;
                if(ch == '-') {
                        vals.erase(vals.find(cnt[x]));
                        --cnt[x];
                        if(cnt[x] > 0) vals.insert(cnt[x]);
                }
                else {
                        vals.erase(vals.find(cnt[x]));
                        ++cnt[x];
                        vals.insert(cnt[x]);
                }
                auto it = vals.end();
                ll a = 0, b = 0, c = 0;
                if(vals.size() >= 1) {
                        --it;
                        a = *it;
                }
                if(vals.size() >= 2) {
                        --it;
                        b = *it;
                }
                if(vals.size() >= 3) {
                        --it;
                        c = *it;
                }
                bool ok = 0;

                if(a >= 8) ok = 1;
                if(a >= 6 && b >= 2) ok = 1;
                if(a >= 4 && b >= 4) ok = 1;
                if(a >= 4 && b >= 2 && c >= 2) ok = 1;

                if(ok) cout << "YES\n";
                else cout << "NO\n";
        }
}

int main() {
        ios::sync_with_stdio(0);
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> > setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

void solve() {
        ll n, q;
        cin >> n;
        vec a(n);
        setpi s;
        mseti vals;
        for(auto &it : a) {
                cin >> it;
                auto ite = s.lower_bound({it, 0});
                if(ite == s.end()) {
                        s.insert({it, 1});
                }
                else {
                        ll x = ite->first;
                        ll y = ite->second;
                        s.erase(ite);
                        ++y;
                        s.insert({x, y});
                }
        }

        for(auto &it : s) {
                vals.insert(it.second);
        }

        cin >> q;
        while(q--) {
                char ch;
                ll p;
                cin >> ch >> p;
                if(ch == '-') {
                        auto it = s.lower_bound({p, 0});
                        ll x = it->first;
                        ll y = it->second;
                        s.erase(it);
                        vals.erase(vals.find(y));
                        --y;
                        if(y > 0) s.insert({x, y}), vals.insert(y);
                }
                else {
                        auto it = s.lower_bound({p, 0});
                        ll x = it->first;
                        ll y = it->second;
                        s.erase(it);
                        vals.erase(vals.find(y));
                        ++y;
                        s.insert({x, y});
                        vals.insert(y);
                }
                bool ok = 0;
                if(vals.size() >= 1) {
                        auto it = vals.end();
                        --it;
                        ll val = *it;
                        if(val >= 8) ok = 1;
                }
                if(vals.size() >= 2) {
                        auto it1 = vals.end();
                        auto it2 = vals.end();

                        --it1;
                        --it2;
                        --it2;
                        ll val1 = *it1;
                        ll val2 = *it2;
                        if(val1 >= 4 && val2 >= 4) ok = 1;
                        if(val1 >= 6 && val2 >= 2) ok = 1;
                }
                if(vals.size() >= 3) {
                        auto it1 = vals.end();
                        auto it2 = vals.end();
                        auto it3 = vals.end();
                        --it1;
                        --it2;
                        --it2;
                        --it3;
                        --it3;
                        --it3;
                        ll val1 = *it1;
                        ll val2 = *it2;
                        ll val3 = *it3;
                        if(val1 >= 4 && val2 >= 2 && val3 >= 2) ok = 1;
                }
                if(ok) {
                        cout << "YES\n";
                }
                else {
                        cout << "NO\n";
                }
        }
}

int main() {
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> >      setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

int cnt[100005];
multiset<int> vals;

void solve() {
        int n, q;
        cin >> n;
        for(int i = 1, x; i <= n; ++i) {
                cin >> x;
                ++cnt[x];
        }
        for(int i = 1; i <= n; ++i)
                if(cnt[i] > 0) vals.insert(cnt[i]);
        cin >> q;
        while(q--) {
                char ch;
                int x;
                cin >> ch >> x;
                if(ch == '-') {
                        vals.erase(vals.find(cnt[x]));
                        --cnt[x];
                        if(cnt[x] > 0) vals.insert(cnt[x]);
                }
                else {
                        vals.erase(vals.find(cnt[x]));
                        ++cnt[x];
                        vals.insert(cnt[x]);
                }
                auto it = vals.end();
                int a = 0, b = 0, c = 0;
                if(vals.size() >= 1) {
                        --it;
                        a = *it;
                        if(a >= 8) {
                                cout << "YES\n";
                                continue;
                        }
                }
                if(vals.size() >= 2) {
                        --it;
                        b = *it;
                        if(a >= 6 && b >= 2 || a >= 4 && b >= 4) {
                                cout << "YES\n";
                                continue;
                        }
                }
                if(vals.size() >= 3) {
                        --it;
                        c = *it;
                        if(a >= 4 && b >= 2 && c >= 2) {
                                cout << "YES\n";
                                continue;
                        }
                }
                cout << "NO\n";
        }
}

int main() {
        ios::sync_with_stdio(0);
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> > setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

ll bit[200005];

void add(ll pos, ll val) {
        for(ll k = pos; k <= 2e5; k += (k & -k)) bit[k] += val;
}

ll sum(ll pos) {
        ll s = 0;
        for(ll k = pos; k > 0; k -= (k & -k)) s += bit[k];
        return s;
}

ll qry(ll pos) {
        if(pos == 1) return sum(1);
        return sum(pos) - sum(pos - 1);
}

void solve() {
        ll n, q;
        cin >> n;
        set<pair<ll, ll>> s;
        for(int i = 0, x; i < n; ++i) {
                cin >> x;
                add(x, 1);
        }
        cin >> q;
        for(int i = 1; i <= 100000; ++i)
                if(qry(i) > 0)
                        s.insert({qry(i), i});

        while(s.size() > 3) s.erase(s.begin());
        while(q--) {
                char ch;
                ll p;
                cin >> ch >> p;
                if(ch == '+') {
                        ll v = qry(p);
                        add(p, 1);
                        auto it = s.find({v, p});
                        if(it == s.end()) {
                                s.insert({v + 1, p});
                        }
                        else {
                                s.erase(it);
                                s.insert({v + 1, p});
                        }
                }
                else {
                        ll v = qry(p);
                        add(p, -1);
                        auto it = s.find({v, p});
                        if(it == s.end()) {
                                if(v > 1) s.insert({v - 1, p});
                        }
                        else {
                                s.erase(it);
                                if(v > 1) s.insert({v - 1, p});
                        }
                }

                while(s.size() > 3) s.erase(s.begin());
                auto it = s.end();

                ll a, b, c;
                a = b = c = 0;

                if(s.size() >= 1) {
                        --it;
                        a = it->first;
                }
                if(s.size() >= 2) {
                        --it;
                        b = it->first;
                }
                if(s.size() >= 3) {
                        --it;
                        c = it->first;
                }

                bool ok = 0;

                if(a >= 8) ok = 1;
                if(a >= 4 && b >= 4) ok = 1;
                if(a >= 6 && b >= 2) ok = 1;
                if(a >= 4 && b >= 2 && c >= 2) ok = 1;

                if(ok) cout << "YES\n";
                else cout << "NO\n";
        }
}

int main() {
        ios::sync_with_stdio(0);
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> >      setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

ll cnt[100005];
multiset<ll> vals;

void solve() {
        ll n, q;
        cin >> n;
        for(ll i = 1, x; i <= n; ++i) {
                cin >> x;
                ++cnt[x];
        }
        for(int i = 1; i <= n; ++i)
                if(cnt[i] > 0) vals.insert(cnt[i]);
        cin >> q;
        while(q--) {
                char ch;
                ll x;
                cin >> ch >> x;
                if(ch == '-') {
                        vals.erase(vals.find(cnt[x]));
                        --cnt[x];
                        if(cnt[x] > 0) vals.insert(cnt[x]);
                }
                else {
                        vals.erase(vals.find(cnt[x]));
                        ++cnt[x];
                        vals.insert(cnt[x]);
                }
                auto it = vals.end();
                ll a = 0, b = 0, c = 0;
                if(vals.size() >= 1) {
                        --it;
                        a = *it;
                        if(a >= 8) {
                                cout << "YES\n";
                                continue;
                        }
                }
                if(vals.size() >= 2) {
                        --it;
                        b = *it;
                        if(a >= 6 && b >= 2 || a >= 4 && b >= 4) {
                                cout << "YES\n";
                                continue;
                        }
                }
                if(vals.size() >= 3) {
                        --it;
                        c = *it;
                        if(a >= 4 && b >= 2 && c >= 2) {
                                cout << "YES\n";
                                continue;
                        }
                }
                cout << "NO\n";
        }
}

int main() {
        ios::sync_with_stdio(0);
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> > setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

ll bit[100005];

void add(ll pos, ll val) {
        for(ll k = pos; k <= 1e5; k += (k & -k)) bit[k] += val;
}

ll sum(ll pos) {
        ll s = 0;
        for(ll k = pos; k > 0; k -= (k & -k)) s += bit[k];
        return s;
}

ll qry(ll pos) {
        return sum(pos) - sum(pos - 1);
}

void solve() {
        ll n, q;
        cin >> n;
        multiset<pair<ll, ll>> s;
        for(int i = 0, x; i < n; ++i) {
                cin >> x;
                add(x, 1);
        }
        cin >> q;
        for(int i = 1; i <= 100000; ++i)
                if(qry(i) > 0)
                        s.insert({qry(i), i});

        while(s.size() > 3) s.erase(s.begin());
        while(q--) {
                char ch;
                ll p;
                cin >> ch >> p;
                if(ch == '+') {
                        ll v = qry(p);
                        add(p, 1);
                        auto it = s.find({v, p});
                        if(it == s.end()) {
                                s.insert({v + 1, p});
                        }
                        else {
                                s.erase(it);
                                s.insert({v + 1, p});
                        }
                }
                else {
                        ll v = qry(p);
                        add(p, -1);
                        auto it = s.find({v, p});
                        if(it == s.end()) {
                                if(v > 1) s.insert({v - 1, p});
                        }
                        else {
                                s.erase(it);
                                if(v > 1) s.insert({v - 1, p});
                        }
                }

                while(s.size() > 3) s.erase(s.begin());
                auto it = s.end();

                ll a, b, c;
                a = b = c = 0;

                if(s.size() >= 1) {
                        --it;
                        a = it->first;
                }
                if(s.size() >= 2) {
                        --it;
                        b = it->first;
                }
                if(s.size() >= 3) {
                        --it;
                        c = it->first;
                }

                bool ok = 0;

                if(a >= 8) ok = 1;
                if(a >= 4 && b >= 4) ok = 1;
                if(a >= 6 && b >= 2) ok = 1;
                if(a >= 4 && b >= 2 && c >= 2) ok = 1;

                if(ok) cout << "YES\n";
                else cout << "NO\n";
        }
}

int main() {
        ios::sync_with_stdio(0);
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> >      setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

ll cnt[100005];
multiset<ll> vals;

void solve() {
        ll n, q;
        cin >> n;
        for(ll i = 1, x; i <= n; ++i) {
                cin >> x;
                ++cnt[x];
        }
        for(int i = 1; i <= n; ++i)
                if(cnt[i] > 0) vals.insert(cnt[i]);
        while(vals.size() > 3) vals.erase(vals.begin());
        cin >> q;
        while(q--) {
                char ch;
                ll x;
                cin >> ch >> x;
                if(ch == '-') {
                        if(vals.count(cnt[x])) {
                                auto it = vals.find(cnt[x]);
                                vals.erase(it);
                                --cnt[x];
                                vals.insert(cnt[x]);
                        }
                        else {
                                --cnt[x];
                                vals.insert(cnt[x]);
                        }
                }
                else {
                        if(vals.count(cnt[x])) {
                                auto it = vals.find(cnt[x]);
                                vals.erase(it);
                                ++cnt[x];
                                vals.insert(cnt[x]);
                        }
                        else {
                                ++cnt[x];
                                vals.insert(cnt[x]);
                        }
                }
                while(vals.size() > 3) vals.erase(vals.begin());
                auto it = vals.end();
                ll a = 0, b = 0, c = 0;
                if(vals.size() >= 1) {
                        --it;
                        a = *it;
                }
                if(vals.size() >= 2) {
                        --it;
                        b = *it;
                }
                if(vals.size() >= 3) {
                        --it;
                        c = *it;
                }
                bool ok = 0;

                if(a >= 8) ok = 1;
                if(a >= 6 && b >= 2) ok = 1;
                if(a >= 4 && b >= 4) ok = 1;
                if(a >= 4 && b >= 2 && c >= 2) ok = 1;

                if(ok) cout << "YES\n";
                else cout << "NO\n";
        }
}

int main() {
        ios::sync_with_stdio(0);
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> > setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

int cnt[100005];
multiset<int> vals;

void solve() {
        int n, q;
        cin >> n;
        for(int i = 1, x; i <= n; ++i) {
                cin >> x;
                ++cnt[x];
        }
        for(int i = 1; i <= 1e5; ++i)
                if(cnt[i] > 0) vals.insert(cnt[i]);
        cin >> q;
        while(q--) {
                char ch;
                int x;
                cin >> ch >> x;
                if(ch == '-') {
                        vals.erase(vals.find(cnt[x]));
                        --cnt[x];
                        if(cnt[x] > 0) vals.insert(cnt[x]);
                }
                else {
                        if(cnt[x] != 0) vals.erase(vals.find(cnt[x]));
                        ++cnt[x];
                        vals.insert(cnt[x]);
                }

                auto it = vals.end();
                int a = 0, b = 0, c = 0;
                if(vals.size() >= 1) {
                        --it;
                        a = *it;
                        if(a >= 8) {
                                cout << "YES\n";
                                continue;
                        }
                }
                if(vals.size() >= 2) {
                        --it;
                        b = *it;
                        if((a >= 6 && b >= 2) || (a >= 4 && b >= 4)) {
                                cout << "YES\n";
                                continue;
                        }
                }
                if(vals.size() >= 3) {
                        --it;
                        c = *it;
                        if(a >= 4 && b >= 2 && c >= 2) {
                                cout << "YES\n";
                                continue;
                        }
                }
                cout << "NO\n";

        }
}

int main() {
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> > setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

ll bit[200005];

void add(ll pos, ll val) {
        for(ll k = pos; k <= 1e5; k += (k & -k)) bit[k] += val;
}

ll sum(ll pos) {
        ll s = 0;
        for(ll k = pos; k > 0; k -= (k & -k)) s += bit[k];
        return s;
}

ll qry(ll pos) {
        return sum(pos) - sum(pos - 1);
}

void solve() {
        ll n, q;
        cin >> n;
        for(int i = 0, x; i < n; ++i) {
                cin >> x;
                add(x, 1);
        }
        cin >> q;
        mseti vals;
        for(int i = 1; i <= n; ++i)
                if(qry(i) > 0) vals.insert(qry(i));
        while(q--) {
                char ch;
                ll p;
                cin >> ch >> p;
                if(ch == '+') {
                        ll v = qry(p);
                        vals.erase(vals.find(v));
                        add(p, 1);
                        vals.insert(v + 1);
                }
                else {
                        ll v = qry(p);
                        vals.erase(vals.find(v));
                        add(p, -1);
                        if(v > 1) vals.insert(v - 1);
                }

                auto it = vals.end();

                ll a, b, c;
                a = b = c = 0;

                if(vals.size() >= 1) {
                        --it;
                        a = *it;
                }
                if(vals.size() >= 2) {
                        --it;
                        b = *it;
                }
                if(vals.size() >= 3) {
                        --it;
                        c = *it;
                }
                bool ok = 0;

                if(a >= 8) ok = 1;
                if(a >= 4 && b >= 4) ok = 1;
                if(a >= 6 && b >= 2) ok = 1;
                if(a >= 4 && b >= 2 && c >= 2) ok = 1;

                if(ok) cout << "YES\n";
                else cout << "NO\n";
        }
}

int main() {
        ios::sync_with_stdio(0);
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> > setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

ll bit[200005];

void add(ll pos, ll val) {
        for(ll k = pos; k <= 1e5; k += (k & -k)) bit[k] += val;
}

ll sum(ll pos) {
        ll s = 0;
        for(ll k = pos; k > 0; k -= (k & -k)) s += bit[k];
        return s;
}

ll qry(ll pos) {
        return sum(pos) - sum(pos - 1);
}

void solve() {
        ll n, q;
        cin >> n;
        multiset<pair<ll, ll>> s;
        for(int i = 0, x; i < n; ++i) {
                cin >> x;
                add(x, 1);
        }
        cin >> q;
        for(int i = 1; i <= n; ++i)
                if(qry(i) > 0)
                        s.insert({qry(i), i});

        while(s.size() > 3) s.erase(s.begin());
        while(q--) {
                char ch;
                ll p;
                cin >> ch >> p;
                if(ch == '+') {
                        ll v = qry(p);
                        add(p, 1);
                        auto it = s.find({v, p});
                        if(it == s.end()) {
                                s.insert({v + 1, p});
                        }
                        else {
                                s.erase(it);
                                s.insert({v + 1, p});
                        }
                }
                else {
                        ll v = qry(p);
                        add(p, -1);
                        auto it = s.find({v, p});
                        if(it == s.end()) {
                                if(v > 1) s.insert({v - 1, p});
                        }
                        else {
                                s.erase(it);
                                if(v > 1) s.insert({v - 1, p});
                        }
                }

                while(s.size() > 3) s.erase(s.begin());
                auto it = s.end();

                ll a, b, c;
                a = b = c = 0;

                if(s.size() >= 1) {
                        --it;
                        a = it->first;
                }
                if(s.size() >= 2) {
                        --it;
                        b = it->first;
                }
                if(s.size() >= 3) {
                        --it;
                        c = it->first;
                }

                bool ok = 0;

                if(a >= 8) ok = 1;
                if(a >= 4 && b >= 4) ok = 1;
                if(a >= 6 && b >= 2) ok = 1;
                if(a >= 4 && b >= 2 && c >= 2) ok = 1;

                if(ok) cout << "YES\n";
                else cout << "NO\n";
        }
}

int main() {
        ios::sync_with_stdio(0);
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


#include <iostream>
#include <vector>

void Can_Build(int* list)
{
	int amount;
	bool sqr = 0, rect_1 = 0, rect_2 = 0;
	for(int i = 0; i < 100001; i++)
	{
		amount = list[i];

		if(!sqr && amount >= 4)
		{
			amount -= 4;
			sqr = 1;
		}

		if(!rect_1 && amount >= 2)
		{
			amount -= 2;
			rect_1 = 1;
		}

		if(rect_1 && amount >= 2)
		{
			rect_2 = 1;
		}

		if(sqr && rect_1 && rect_2)
		{
			std::cout << "YES\n";
			return;
		}
	}

	std::cout << "NO\n";
}

int main()
{
	int t,value;
	char ch;
	std::cin >> t;
	int *list = new int[100001];
	for (int i = 0; i < 100001; i++) { list[i] = 0; }
	for(int i = 0; i<t; i++)
	{
		std::cin >> value;
		list[value]++;

	}
	std::cin >> t;
	for(int i = 0; i<t; i++)
	{
		std::cin >> ch >> value;
		if(ch == '+')
		{
			list[value]++;
		}

		else if(ch == '-')
		{
			list[value]--;
		}

		Can_Build(list);
	}
}


#include <iostream>
#include <vector>

class Planck_List
{
public:
	int m_size;
	int m_amount;

	Planck_List(int size)
	: m_size(size), m_amount(1) {}
};

void Put_Planck(std::vector<Planck_List>& list, int value, int &size)
{
	for(int i = 0; i < size; i++)
	{
		if (list[i].m_size == value)
		{
			list[i].m_amount++;
			return;
		}
	}
	size++;
	list.emplace_back(Planck_List(value));

}

void Remove_Planck(std::vector<Planck_List>& list, int value, int size)
{
	for (int i = 0; i < size; i++)
	{
		if (list[i].m_size == value)
		{
			list[i].m_amount--;
			return;
		}
	}
}

void Can_Build(std::vector<Planck_List> &list, int size)
{
	bool square = 0, rectangle_x = 0, rectangle_y = 0;
	int amount;
	for(int i = 0; i < size; i++)
	{
		amount = list[i].m_amount;
		if (!square && amount >= 4)
		{
			square = 1;
			amount -= 4;
		}

		if(!rectangle_x && amount >= 2)
		{
			rectangle_x = 1;
			amount -= 2;
		}

		if(rectangle_x && !rectangle_y && amount >= 2)
		{
			rectangle_y = 1;
			amount -= 2;
		}

		if (square && rectangle_x && rectangle_y)
		{
			std::cout << "YES\n";
			return;
		}
	}

	std::cout << "NO\n";
}

int main()
{
	int t,value,size;
	char ch;
	std::cin >> t;
	std::vector<Planck_List> list;
	for(int i = 0; i<t; i++)
	{
		std::cin >> value;
		Put_Planck(list, value, size);
	}
	std::cin >> t;
	for(int i = 0; i<t; i++)
	{
		std::cin >> ch >> value;
		if(ch == '+')
		{
			Put_Planck(list, value, size);
		}
		else if(ch == '-')
		{
			Remove_Planck(list, value, size);
		}

		Can_Build(list, size);
	}
}


#include <iostream>
#include <vector>

int main()
{
	int t,value;
	char ch;
	std::cin >> t;
	int *list = new int[100001];
	int rect = 0, sqr = 0;
	for (int i = 0; i < 10001; i++) { list[i] = 0;}
	for(int i = 0; i<t; i++)
	{
		std::cin >> value;
		list[value]++;
		if (list[value] % 4 == 0 && list[value] != 0) {
			sqr++, rect--;
		}
		else if(list[value] % 2 == 0 && list[value] != 0) rect++;

	}
	std::cin >> t;
	for(int i = 0; i<t; i++)
	{
		std::cin >> ch >> value;
		if(ch == '+')
		{
			list[value]++;

			if (list[value] % 4 == 0 && list[value] != 0)
			{
				sqr++, rect--;
			}
			else if (list[value] % 2 == 0 && list[value] != 0) rect++;

		}

		else if(ch == '-')
		{
			list[value]--;

			if (list[value] % 4 == 3)
			{
				sqr--, rect++;
			}
			else if (list[value] % 2 == 1) rect--;

		}

		if ((rect >= 2 && sqr >= 1) || sqr >= 2) std::cout << "YES\n";
		else std::cout << "NO\n";
	}
}


#include <iostream>
#include <vector>

void Can_Build(int* list)
{
	int amount;
	bool sqr = 0, rect_1 = 0, rect_2 = 0;
	for(int i = 0; i < 10001; i++)
	{
		amount = list[i];

		if (amount == 0) continue;

		if(!sqr && amount >= 4)
		{
			amount -= 4;
			sqr = 1;
		}

		if (amount == 0) continue;

		if(!rect_1 && amount >= 2)
		{
			amount -= 2;
			rect_1 = 1;
		}

		if (amount == 0) continue;

		if(!rect_1 && rect_2 && amount >= 2)
		{
			amount -= 2;
			rect_2 = 1;
		}

		if(sqr && rect_1 && rect_2)
		{
			std::cout << "YES\n";
			return;
		}
	}

	std::cout << "NO\n";
}

int main()
{
	int t,value;
	char ch;
	std::cin >> t;
	int list[10001] = { 0 };
	for(int i = 0; i<t; i++)
	{
		std::cin >> value;
		list[value]++;

	}
	std::cin >> t;
	for(int i = 0; i<t; i++)
	{
		std::cin >> ch >> value;
		if(ch == '+')
		{
			list[value]++;
		}

		else if(ch == '-')
		{
			list[value]--;
		}

		Can_Build(list);
	}
}


#include <iostream>
#include <vector>

void Can_Build(int* list)
{
	int amount;
	bool sqr = 0, rect_1 = 0, rect_2 = 0;
	for(int i = 0; i < 10001; i++)
	{
		amount = list[i];

		if(!sqr && amount >= 4)
		{
			amount -= 4;
			sqr = 1;
		}

		if(!rect_1 && amount >= 2)
		{
			amount -= 2;
			rect_1 = 1;
		}

		if(rect_1 && amount >= 2)
		{
			rect_2 = 1;
		}

		if(sqr && rect_1 && rect_2)
		{
			std::cout << "YES\n";
			return;
		}
	}

	std::cout << "NO\n";
}

int main()
{
	int t,value;
	char ch;
	std::cin >> t;
	int *list = new int[10001];
	for (int i = 0; i < 10001; i++) { list[i] = 0; }
	for(int i = 0; i<t; i++)
	{
		std::cin >> value;
		list[value]++;

	}
	std::cin >> t;
	for(int i = 0; i<t; i++)
	{
		std::cin >> ch >> value;
		if(ch == '+')
		{
			list[value]++;
		}

		else if(ch == '-')
		{
			list[value]--;
		}

		Can_Build(list);
	}
}


#include <iostream>
#include <vector>

class Planck_List
{
public:
	int m_size;
	int m_amount;

	Planck_List(int size)
	: m_size(size), m_amount(1) {}
};

void Put_Planck(std::vector<Planck_List>& list, int value)
{
	for(int i = 0; i < list.size(); i++)
	{
		if (list[i].m_size == value)
		{
			list[i].m_amount++;
			return;
		}
	}

	list.push_back(Planck_List(value));

}

void Remove_Planck(std::vector<Planck_List>& list, int value)
{
	for (int i = 0; i < list.size(); i++)
	{
		if (list[i].m_size == value)
		{
			list[i].m_amount--;
			return;
		}
	}
}

void Can_Build(std::vector<Planck_List> &list)
{
	bool square = 0, rectangle_x = 0, rectangle_y = 0;
	int amount;
	for(int i = 0; i < list.size(); i++)
	{
		amount = list[i].m_amount;
		if (!square && amount >= 4)
		{
			square = 1;
			amount -= 4;
		}

		if(!rectangle_x && amount >= 2)
		{
			rectangle_x = 1;
			amount -= 2;
		}

		if(rectangle_x && !rectangle_y && amount >= 2)
		{
			rectangle_y = 1;
			amount -= 2;
		}

		if (square && rectangle_x && rectangle_y)
		{
			std::cout << "YES\n";
			return;
		}
	}

	std::cout << "NO\n";
}

int main()
{
	int t,value;
	std::cin >> t;
	std::vector<Planck_List> list;
	for(int i = 0; i<t; i++)
	{
		std::cin >> value;
		Put_Planck(list, value);
	}
	int n;
	std::cin >> n;
	char ch;
	while(n--)
	{
		std::cin >> ch >> value;
		if(ch == '+')
		{
			Put_Planck(list, value);
		}
		else if(ch == '-')
		{
			Remove_Planck(list, value);
		}

		Can_Build(list);
	}
}


#include <iostream>
#include <vector>

void Can_Build(int* list)
{
	int amount;
	bool sqr = 0, rect_1 = 0, rect_2 = 0;
	for(int i = 0; i < 10001; i++)
	{
		amount = list[i];

		if (amount == 0) continue;

		if(!sqr && amount >= 4)
		{
			amount -= 4;
			sqr = 1;
		}

		if (amount < 2) continue;

		if(!rect_1)
		{
			amount -= 2;
			rect_1 = 1;
		}

		if (amount < 2) continue;

		if(rect_1)
		{
			rect_2 = 1;
		}

		if(sqr && rect_1 && rect_2)
		{
			std::cout << "YES\n";
			return;
		}
	}

	std::cout << "NO\n";
}

int main()
{
	int t,value;
	char ch;
	std::cin >> t;
	int list[10001] = { 0 };
	for(int i = 0; i<t; i++)
	{
		std::cin >> value;
		list[value]++;

	}
	std::cin >> t;
	for(int i = 0; i<t; i++)
	{
		std::cin >> ch >> value;
		if(ch == '+')
		{
			list[value]++;
		}

		else if(ch == '-')
		{
			list[value]--;
		}

		Can_Build(list);
	}
}