#include <bits/stdc++.h>
#define vec vector
#define For(i, n) for(int i = 0; i < n; i++)
#define int long long
#define ld long double
#define mod 1000000007
#define all(x) x.begin(), x.end()
using namespace std;
vec<vec<int>> comb(vec<vec<int>>& a, vec<vec<int>>&b){
int n = a.size();
vec<vec<int>> vys(n, vec<int>(n, 0));
For(i, n) For(j, n) For(k, n) vys[i][j] = (vys[i][j] + a[i][k] * b[k][j]) % mod;
return vys;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int r, c, q; cin >> r >> c >> q; r--;
vec<vec<int>> mat[32];
For(i, 32) mat[i].assign(c, vec<int>(c, 0));
For(i, c) for(int j = i-1; j < c && j <= i+1; j++) if(j >= 0) mat[0][i][j] = 1;
For(i, 31) mat[i+1] = comb(mat[i], mat[i]);
vec<vec<int>> zac(c, vec<int>(c, 0));
For(i, c) zac[i][i] = 1;
For(i, 32) if(r & (1<<i)) zac = comb(zac, mat[i]);
For(i, q){
char t; cin >> t;
if(t == 'K'){
int c1, c2; cin >> c1 >> c2; c1--;c2--;
cout << r << ' ' << zac[c2][c1] << endl;
}
}
return 0;
}