#include <iostream>
#include <string>
#include <cstring>
#include <queue>
using namespace std;

class Ans
{
public:
	int p,t,l;
	Ans(int p, int t, int l)
		:p(p),t(t),l(l)
	{}

	bool operator<(const Ans& ans) const
	{
		return t>ans.t;
	}
};

int M,N,D[100];
int ssend, srecv;
int psend[100], precv[100];

void calc(priority_queue<Ans>& q)
{
	int tt=1,ansn=0,ansl=0,alansn=0, alansl=0;
	bool ansed[100]={0},nwansed[100]={0};
	int lg[100]={0};
	
	q.push(Ans(0,99999,0));

	while(1)
	{
		Ans a=q.top(); 
		if(tt > 20) break;
		
		if(a.t < tt*1000) 
		{
			ansed[a.p]=1;
			nwansed[a.p]=1;
			
			ansn++;
			ansl+=a.l;
			alansn++;
			alansl+=a.l;
			
			lg[a.p]=a.l;
			
			q.pop();
		}
		else
		{
			++tt;
			if(ansn==0) continue;
			
			for(int i=0; i<M; i++)
			{
				if(nwansed[i])
				{
					if(alansn>1)
					{
						ssend+=4+2*(alansn-1)+(alansl-lg[i]);
						precv[i]+=4+2*(alansn-1)+(alansl-lg[i]);
					}
				}
				else if(ansed[i])
				{
					ssend+=4+2*ansn+ansl;
					precv[i]+=4+2*ansn+ansl;
				}
				else
				{
					ssend+=4+ansn;
					precv[i]+=4+ansn;
				}
				
			}
			
			ansn=0;
			ansl=0;
			memset(lg,0,sizeof(lg));
			memset(nwansed, 0, sizeof(nwansed));
		}
	}
}

int main()
{
	bool b=0;
	while(cin >> M >> N, (M||N))
	{
		if(b) cout << endl;
		b=1;
		
		for(int i=0; i<M; i++)
			cin >> D[i];

		ssend=0;
		srecv=0;
		memset(psend,0,sizeof(psend));
		memset(precv,0,sizeof(precv));

		for(int i=0; i<N; i++)
		{
			ssend+=3*M;
			for(int j=0; j<M; j++)
				precv[j]+=3;
			
			int L;
			cin >> L;
			priority_queue<Ans> q;
			for(int j=0; j<L; j++)
			{
				int P,T;
				string A;
				cin >> P >> T >> A;
				q.push(Ans(P,T+D[P]*2,A.size()));

				psend[P]+=5+A.size();
				srecv+=5+A.size();
			}

			calc(q);
			ssend+=4*M;
			for(int j=0; j<M; j++)
				precv[j]+=4;
			
		}

		cout << ssend << " " << srecv << endl;
		for(int i=0; i<M; i++)
			cout << psend[i] << " " << precv[i] << endl;
	}
}