#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;

struct Answer{
  int player;
  int time_sent;
  int time_rec;
  string answer;
};

int main()
{
  int n, m;
  bool first = true;
  while( cin >> n >> m && n && m ){
    int delay[n];
    int server_sent = 0;
    int server_rec  = 0;
    int sent[n];
    int rec[n];

    if( !first ){
      cout << endl;
    }else first = false;
    
    for(int i = 0; i < n; ++i){
      cin >> delay[i];
      sent[i] = 0;
      rec[i] = 0;
    }

    for(int prob = 0; prob < m; ++prob){
      int L;
      map<int,vector<Answer> > all_ans;

      // problem-start
      server_sent += 3*n;
      for(int i = 0; i < n; ++i){
        rec[i] += 3;
      }
      
      cin >> L;
      for(int i = 0; i < L; ++i){
        Answer ans;
        cin >> ans.player >> ans.time_sent >> ans.answer;
        //cout << ans.player << ' ' << ans.time_sent << ' ' << ans.answer << endl;
        ans.time_rec = ans.time_sent + 2*delay[ans.player];
        all_ans[ ans.time_rec ].push_back( ans );
        
        server_rec += 3+1+1+ans.answer.length();
        sent[ans.player] += 3+1+1+ans.answer.length();
      }

      int time = 1000;
      bool old_submit[n];
      bool new_submit[n];
      Answer submit_answer[n];
      vector<Answer> old_ans;
      vector<Answer> new_ans;
      
      for(int i = 0; i < n; ++i){
        old_submit[i] = false;
        new_submit[i] = false;
      }

      while(time <= 20000 ){
        //cout << "TIME : <" << time << endl;
        for(int i = 0; i < (int)new_ans.size(); ++i){
          old_ans.push_back( new_ans[i] );
        }
        for(int i = 0; i < n; ++i){
          //cout << sent[i] << ' ' << rec[i] << endl;
          if( new_submit[i] ){
            old_submit[i] = new_submit[i];
          }
        }
        //cout << endl;

        new_ans.clear();
        for(int i = 0; i < n; ++i){
          new_submit[i] = false;
        }
  
        //cout << endl;

        map<int,vector<Answer> >::iterator it = all_ans.lower_bound(time - 1000);
        for(;it!=all_ans.end()&&it->first<time;++it){
          // for newly recieved
          //cout << it->first <<endl;
          for(int i = 0; i < (int)it->second.size(); ++i){
            new_ans.push_back( it->second[i] );
            new_submit[ it->second[i].player ] = true;
            submit_answer[ it->second[i].player ] = it->second[i];
          }
        }


        for(int i = 0; i < n; ++i){
          //cout << old_submit[i]  << ' ' << new_submit[i] << endl;
        }
        
        
        for(int i = 0; i < n; ++i){
          if( !old_submit[i] && !new_submit[i] ){
            // not yet submitted
            int sent_b = 3+1+new_ans.size();
            if( new_ans.size() > 0 ){
              server_sent += sent_b;
              rec[i] += sent_b;
            }
            //cout << new_ans.size() << ' ' << "not yet " << i << ' ' << sent_b << endl;
          }
          else if( old_submit[i] && !new_submit[i] ){
            // submitted but not newly
            int sent_b = 3+1;
            int cnt=0;
            for(int j = 0; j < (int)new_ans.size(); ++j){
              ++cnt;
              sent_b += 1+1+new_ans[j].answer.length();
            }
            if( cnt > 0 ){
              server_sent += sent_b;
              rec[i] += sent_b;
            }
            //cout << cnt << " old submit " << i << ' ' << sent_b << endl;
          }
          else if( new_submit[i] ){
            // submitted newly
            int sent_b = 3+1;
            int cnt = 0;
            for(int j = 0; j < (int)new_ans.size(); ++j){
              if( new_ans[j].player != i ){
                ++cnt;
                sent_b += 1+1+new_ans[j].answer.length();
              }
            }
            for(int j = 0; j < (int)old_ans.size(); ++j){
              if( old_ans[j].player != i ){
                ++cnt;
                sent_b += 1+1+old_ans[j].answer.length();
              }
            }
            
            if( cnt > 0 ){
              server_sent += sent_b;
              rec[i] += sent_b;
            }
            //cout << cnt << " newly " << i << ' ' << sent_b << endl;
          }
        }
 
        time += 1000;
      }
      // problem-end
      server_sent += 4*n;
      for(int i = 0; i < n; ++i){
        rec[i] += 4;
      }
      
    }


    cout << server_sent << ' ' << server_rec << endl;
    for(int i = 0; i < n; ++i){
      cout << sent[i] << ' ' << rec[i] << endl;
    }

  }
  return 0;
}

Measured memory_bytes: 952