var n,k,i:longint;
s,t,r:array[1..100000]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
if n mod (s[i]*t[i])=0 then
writeln((n div (s[i]*t[i]))*(t[i]+r[i])+(n mod (s[i]*t[i])div s[i])-r[i])
else
writeln((n div (s[i]*t[i]))*(t[i]+r[i])+(n mod (s[i]*t[i])div s[i]))
else
if n mod (s[i]*t[i])=0 then
writeln((n div (s[i]*t[i]))*(t[i]+r[i])+(n mod (s[i]*t[i])div s[i]+1)-r[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.