rendered paste body/*
ID: iamnotnad1
PROG: cows
LANG: JAVA
*/
import java.util.Scanner;
import java.io.*;
class Cows
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner sc=new Scanner(new File("tester.txt"));
int book=sc.nextInt();
int cows=sc.nextInt();
int max=100000, greatest=0, counter=1;
Cow[] array=new Cow[cows];
for(int k=0;k<cows;k++)
array[k]=new Cow(sc.nextInt(),sc.nextInt(),sc.nextInt());
for(int k=0;k<cows;k++)
{
counter=1;
int time=0, pgs=0;
while (pgs<book)
{
if(counter==array[k].getMax())
{
time=time+array[k].getRest();
counter=1;
}
else
{
counter++;
time++;
pgs=pgs+array[k].getSpeed();
}
}
System.out.println("Cow "+(k+1)+" read at "+time);
}
}
}