var n,k,i:longint;
s,t,r:array[1..1000]of longint;
begin
assign(input,'read.in');assign(output,'read.out');reset(input);rewrite(output);
read(n,k);
for i:=1 to k do
read(s[i],t[i],r[i]);
for i:=1 to k do
if n mod (s[i]*t[i]) mod s[i]=0 then
writeln((n div (s[i]*t[i]))*(t[i]+r[i])+(n mod (s[i]*t[i])div s[i]))
else
writeln((n div (s[i]*t[i]))*(t[i]+r[i])+(n mod (s[i]*t[i])div s[i]+1));
close(input);close(output);
end.