interface Packet:Comparable<Packet>{
    val timeStamp:Int
    val size:Int
    override fun compareTo(other: Packet): Int {
        return when(other){
            is Tick -> -other.compareTo(this)
            else -> timeStamp.compareTo(other.timeStamp)
        }
    }
}
abstract class APacket(override val timeStamp:Int, override val size:Int):Packet
interface PacketToServer:Packet
interface PacketToPlayer:Packet
open class Tick(timeStamp: Int):APacket(timeStamp, 0), PacketToServer{
    override fun compareTo(other: Packet): Int {
        return when (other){
            is Tick -> timeStamp.compareTo(other.timeStamp)
            else -> timeStamp.compareTo(other.timeStamp).let{if (it == 0) -1 else it}
        }
    }

    companion object {
        val EverySecond:Iterable<Tick> = (1 .. 20).map{Tick(it * 1000)} + TimerEnd
    }
}
object TimerEnd:Tick(20001)
object SynchronizeStart:APacket(0, 3), PacketToPlayer
object SynchronizeEnd:APacket(20000, 4), PacketToPlayer
class Player(private val mDelay:Int){
    fun setAnswer(time:Int, answer:String):Unit {
        sendPacket = AnswerPacket(time + mDelay * 2, answer)
        sendSize += sendPacket.size
    }
    fun receiveChoicePacket(packetA:OtherPlayersInfo, packetBDiff:OtherPlayersInfo, packetBall:OtherPlayersInfo):Unit {
        //print("${packetA.timeStamp} := ")
        val received = when{
            packetA.timeStamp <= sendPacket.timeStamp && packetA.isNotEmpty -> {
                //print("$this receive packet A")
                packetA.size
            }
            sendPacket.timeStamp < packetBall.timeStamp && packetBall.timeStamp <= (sendPacket.timeStamp + 1000) && (packetBall.size != sendPacket.size + 1) -> {
                //print("$this receive packet B about all player")
                packetBall.size - sendPacket.size + 3
            }
            (sendPacket.timeStamp + 1000) < packetBDiff.timeStamp && packetBDiff.isNotEmpty -> {
                //print("$this receive packet B about diff player")
                packetBDiff.size
            }
            else -> {
                //print("$this receive no packet")
                0
            }
        }
        //println(" receive $received bytes")
        receiveSize += received
    }
    fun receivePacket(packet:PacketToPlayer):Unit {
        //print("${packet.timeStamp} := ")
        when(packet){
            is SynchronizeStart -> {
                //println("$this receive start packet")
                sendPacket = DummyPacket
            }
            else->{
                //println("$this receive end packet")
            }
        }
        receiveSize += packet.size
    }
    var sendPacket:PacketToServer = DummyPacket
        private set
    var receiveSize:Int = 0
        private set
    var sendSize:Int = 0
        private set
}
class AnswerPacket private constructor(timeStamp:Int, answerSize:Int):APacket(timeStamp, answerSize + 5), PacketToServer{
    constructor(timeStamp: Int, answer:String):this(timeStamp, answer.length)
}
interface OtherPlayersInfo: PacketToPlayer{
    val isNotEmpty:Boolean
        get() = false
}
class PacketA(timeStamp: Int, playerCount:Int):APacket(timeStamp, playerCount + 4), PacketToPlayer, OtherPlayersInfo{
    override val isNotEmpty:Boolean = playerCount != 0
}
class PacketB(timeStamp: Int, wholeAnswerSize: Int):APacket(timeStamp, wholeAnswerSize + 4), PacketToPlayer, OtherPlayersInfo{
    override val isNotEmpty:Boolean = wholeAnswerSize != 0
}
object DummyPacket:APacket(100000, 0), PacketToPlayer, PacketToServer, OtherPlayersInfo
fun solve2(n:Int):Unit {
    val players = readLine()!!.split(' ').map{Player(it.toInt())}
    repeat(n){
        players.forEach { it.receivePacket(SynchronizeStart) }
        repeat(readLine()!!.toInt()){
            val (id, time, answer) = readLine()!!.split(' ')
            players[id.toInt()].setAnswer(time.toInt(), answer)
        }
        var wholeAnswerSize:Int = 0
        var newAnsweredSize:Int = 0
        var newAnsweredPlayerNum:Int = 0
        for (receivePacket in (players.map{it.sendPacket} + Tick.EverySecond).sorted()){
            when(receivePacket){
                is TimerEnd -> {
                    players.forEach { it.receivePacket(SynchronizeEnd) }
                }
                is AnswerPacket -> {
                    newAnsweredSize += receivePacket.size - 3
                    ++newAnsweredPlayerNum
                }
                is Tick -> when {
                    (newAnsweredPlayerNum != 0) -> {
                        val packetA = PacketA(receivePacket.timeStamp, newAnsweredPlayerNum)
                        val packetBDiff = PacketB(receivePacket.timeStamp, newAnsweredSize)
                        val packetBall = PacketB(receivePacket.timeStamp, wholeAnswerSize + newAnsweredSize)
                        players.forEach { it.receiveChoicePacket(packetA, packetBDiff, packetBall) }
                        wholeAnswerSize += newAnsweredSize
                        newAnsweredSize = 0
                        newAnsweredPlayerNum = 0
                    }
                    (wholeAnswerSize != 0) -> {
                        val packetBall = PacketB(receivePacket.timeStamp, wholeAnswerSize)
                        players.forEach { it.receiveChoicePacket(DummyPacket, DummyPacket, packetBall) }
                    }
                }
            }
        }
    }
    val server = players.map{Pair(it.receiveSize, it.sendSize)}.fold(Pair(0, 0)){a, b -> Pair(a.first + b.first, a.second + b.second)}
    println("${server.first} ${server.second}")
    players.forEach { println("${it.sendSize} ${it.receiveSize}") }
}
fun main(args:Array<String>):Unit {
    var (m, n) = readLine()!!.split(' ').map(String::toInt)
    while (m != 0 && n != 0){
        solve2(n)
        val (mm, nn) = readLine()!!.split(' ').map(String::toInt)
        m = mm
        n = nn
        if (m != 0 && n != 0) println("")
    }
}
