#include<bits/stdc++.h>
#define M 1000005
using namespace std;
char c[M];
int a[4][M], bk[M];
int main()
{
int n, q;
scanf("%d%d", &n, &q);
scanf("%s", c + 1);
for(int i = 1; i <= n; i++) a[1][n - i + 1] = c[i] - '0';
scanf("%s", c + 1);
for(int i = 1; i <= n; i++) a[2][n - i + 1] = c[i] - '0';
for(int i = 1; i <= n; i++)
{
a[3][i] = a[1][i] + a[2][i];
// cout << i << " " << bk[4] << endl;
bk[i + 1] += ((a[3][i] + bk[i]) > 9);
// cout << i << " " << bk[4] << endl;
a[3][i] %= 10;
// cout << i << " " << bk[4] << endl;
}
int t = a[1][n - 1];
if(t == 1)
{
for(int i = 996454; i <= 996459; i++) cout << a[1][i];
cout << endl;
for(int i = 996454; i <= 996459; i++) cout << a[2][i];
cout << endl;
}
for(int i = 1, r, c, d; i <= q; i++)
{
scanf("%d%d%d", &r, &c, &d);
c = n - c + 1;
if(a[r][c] == d)
{
printf("%d 0\n", (a[3][c] + bk[c]) % 10);
continue;
}
// cout << "LOOK AT HERE:" << i << " " << bk[10] << endl;
int ans = 1;
a[r][c] = d;
// cout << c << " " << bk[4] << endl;
int tk = bk[c], ps = c;
// for(int j = 1; j <= n; j++) cout << a[1][j];
// cout << endl;
// for(int j = 1; j <= n; j++) cout << a[2][j];
// cout << endl;
bool fl;
do{
int nw = a[1][ps] + a[2][ps] + tk;
if(n == 1000000 && t == 1) cout << "Case:" << i << " " << c << " " << d << " " << ps << " " << nw << " " << tk << << endl;
int oritk = tk;
tk = (nw > 9);
// cout << ps + 1 << endl;
nw %= 10;
fl = 0;
// cout << a[3][ps] << " " << bk[ps] << endl;
if(nw != a[3][ps] + bk[ps]) a[3][ps] = nw - oritk, ans++, fl = 1;
bk[ps] = oritk;
ps++;
}while(ps <= n && fl);
bk[ps] = tk;
printf("%d %d\n", a[3][c] + bk[c], ans);
}
// for(int i = 1; i <= n; i++) cout << a[1][n - i + 1];
// cout << endl;
// for(int i = 1; i <= n; i++) cout << a[2][n - i + 1];
return 0;
}