#include<bits/stdc++.h>
using namespace std;
const double PI=acos(-1);
#define int long long
#define double long double
#define endl '\n'
int qmi(int a, int k, int p) { // 求a^k mod p 求a逆元就是(a,p-2,p)
int res = 1 % p;
while (k) {
if (k & 1) res = (__int128) res * a % p;//c++20才可以
a = (__int128) a * a % p;//龟速乘就是把两个*的符号改成+
k >>= 1;
}
return res;
}
int gcd (int a ,int b) {
return b ? gcd ( b , a % b ) :a;
}
const int N=1e5+10;
int a[N];
const int p=998244353;
map<int,int>mp;
int dfs(int x) {
if(x==0) return 1;
if(mp[x]) return mp[x];
mp[x]=dfs(x/2)+dfs(x/3);
return mp[x];
}
signed main() {
int n,m,t;
cin>>n>>m;
cin>>t;
while(t--) {
int k=1,x=1,y=1;
int a,b,c;
cin>>a>>b>>c;
if(a==0&&b==0) {//特判
cout<<k<<" "<<x<<" "<<y<<endl;
continue;
}
else {
int k0=0;//最少多少个c让走向下一层
if(a){
k0=(n-1)/a+1;
}
if(b){
k0=(n-1)/b+1;
}
if(a&&b){
k0=min((n-1)/a,(n-1)/b)+1;
}
k+=c/k0;
c-=c/k0*k0;
}
while(c--) {
x+=a,y+=b;
if(x>n||y>m) {
k++,x=1,y=1;
}
}
cout<<k<<" "<<x<<" "<<y<<endl;
}
return 0;
}
https://ac.nowcoder.com/acm/contest/44246/C