#include <iostream>
using namespace std;
int zsj[1010]={0};
int main() {
freopen("read.in","r",stdin);
freopen("read.out","w",stdout);
int ys,ns;
cin>>ys>>ns;
for(int i=0;i<ns;i++){
int Si,Ti,Ri;
cin>>Si>>Ti>>Ri;
int t=ys/Si;
int zt=t/Ti;
int x=zt*(Ti+Ri);
int sy=ys-t*Si;
double sysj=(double)sy/(double)Si;
zsj[i]=((int)sysj)+x+1;
}
for(int i=0;i<ns;i++) cout<<zsj[i]<<endl;
return 0;
}