#include<bits/stdc++.h>
const int N=4e6+10;
using namespace std;

int n,m,q,op,x;
long long y,aa[N],bb[N],ans;

struct node {
	int ls,rs;
	long long tot,sum;
} A[N],B[N];

int rta=0,cnta=0;
void updateA(int p) {
	A[p].sum=A[A[p].ls].sum+A[A[p].rs].sum;
	A[p].tot=A[A[p].ls].tot+A[A[p].rs].tot;
}
void insertA(int &p,int l,int r,int x,int pos) {
	if(!p) p=++cnta;
	if(l==r) {
		A[p].sum+=pos;
		A[p].tot+=pos*x;
		return;
	}
	int mid=l+r>>1;
	if(x<=mid) insertA(A[p].ls,l,mid,x,pos);
	else insertA(A[p].rs,mid+1,r,x,pos);
	updateA(p);
}
long long queryA1(int p,int l,int r,int pos) {
	if(!p) return 0;
	if(r<=pos) return A[p].sum;
	int mid=l+r>>1;
	if(pos>mid) return A[A[p].ls].sum+queryA1(A[p].rs,mid+1,r,pos);
	else return queryA1(A[p].ls,l,mid,pos);
}
long long queryA2(int p,int l,int r,int pos) {
	if(!p) return 0;
	if(l>pos) return A[p].tot;
	int mid=l+r>>1;
	if(pos<=mid) return A[A[p].rs].tot+queryA2(A[p].ls,l,mid,pos);
	else return queryA2(A[p].rs,mid+1,r,pos);
}

int rtb,cntb;
void updateB(int p) {
	B[p].sum=B[B[p].ls].sum+B[B[p].rs].sum;
	B[p].tot=B[B[p].ls].tot+B[B[p].rs].tot;
}
void insertB(int &p,int l,int r,int x,int pos) {
	if(!p) p=++cntb;
	if(l==r) {
		B[p].sum+=pos;
		B[p].tot+=pos*x;
		return;
	}
	int mid=l+r>>1;
	if(x<=mid) insertB(B[p].ls,l,mid,x,pos);
	else insertB(B[p].rs,mid+1,r,x,pos);
	updateB(p);
}
long long queryB1(int p,int l,int r,int pos) {
	if(!p) return 0;
	if(r<=pos) return B[p].sum;
	int mid=l+r>>1;
	if(pos>mid) return B[B[p].ls].sum+queryB1(B[p].rs,mid+1,r,pos);
	else return queryB1(B[p].ls,l,mid,pos);
}
long long queryB2(int p,int l,int r,int pos) {
	if(!p) return 0;
	if(l>pos) return B[p].tot;
	int mid=l+r>>1;
	if(pos<=mid) return B[B[p].rs].tot+queryB2(B[p].ls,l,mid,pos);
	else return queryB2(B[p].rs,mid+1,r,pos);
}

int main() {
	scanf("%d%d%d",&n,&m,&q);
	insertA(rta,0,1e8,0,n),insertB(rtb,0,1e8,0,m);
	while(q--) {
		scanf("%d%d%lld",&op,&x,&y);
		if(op==1) {
			ans=ans-aa[x]*queryB1(rtb,0,1e8,aa[x])-queryB2(rtb,0,1e8,aa[x]);
			insertA(rta,0,1e8,aa[x],-1);
			insertA(rta,0,1e8,y,1);
			aa[x]=y;
			ans=ans+y*queryB1(rtb,0,1e8,y)+queryB2(rtb,0,1e8,y);
		} else {
			ans=ans-bb[x]*queryA1(rta,0,1e8,bb[x])-queryA2(rta,0,1e8,bb[x]);
			insertB(rtb,0,1e8,bb[x],-1);
			insertB(rtb,0,1e8,y,1);
			bb[x]=y;
			ans=ans+y*queryA1(rta,0,1e8,y)+queryA2(rta,0,1e8,y);
		}
		printf("%lld\n",ans);
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

using P = pair<int, int>;
using PP = pair<double, P>;

const double INF = 1000000010.0;
int di[4] = {0, 0, 1, -1};
int dj[4] = {1, -1, 0, 0};

vector<vector<double>> h;
vector<vector<double>> v;
int si,sj,ti,tj,a;
double e;

vector<vector<double>> dist;
vector<vector<P>> pre;

double get_distance(int itr, int i, int j){
  double dis;
  switch (itr) {
		case 0:
      dis = h[i][j];
      break;
		case 1:
      dis = h[i][j-1];
			break;
    case 2:
      dis = v[i][j];
      break;
		case 3:
      dis = v[i-1][j];
			break;
	}
  return dis;
}

void dijkstra() {
    dist = vector<vector<double> >(30, vector<double>(30, INF));
    pre = vector<vector<P> >(30, vector<P>(30, P(-1, -1)));
    dist[si][sj] = 0;
    priority_queue<PP, vector<PP>, greater<PP> > pq;
    pq.push(PP(0, P(si, sj)));

    while (!pq.empty()) {
        PP p = pq.top();
        pq.pop();
        double c = p.first;
        int vi = p.second.first, vj = p.second.second;

        for (int i = 0; i < 4; i++)
         {
            int ni, nj;
            ni = vi + di[i], nj = vj + dj[i];
            if (ni < 0 || nj < 0 || ni >= 30 || nj >= 30) continue;
            double dis = get_distance(i,vi,vj);
            if (dist[ni][nj] <= dis + c) continue;
            dist[ni][nj] = dis + c;
            pre[ni][nj] = P(vi, vj);
            pq.push(PP(dist[ni][nj], P(ni, nj)));
        }
    }
}

string get_path_str(int diff_i, int diff_j){
  string str = "";
  if(diff_i == -1) str = "D";
  if(diff_i == 1) str = "U";
  if(diff_j == -1) str = "R";
  if(diff_j == 1) str = "L";
  return str;
}

string restore() {
    vector<P> path;
    string path_str = "";

    int i = ti, j = tj;
    int pre_i = pre[i][j].first, pre_j = pre[i][j].second;
    for (; pre_i != -1 || pre_j != -1;) {
        int diff_i = pre_i - i;
        int diff_j = pre_j - j;
        path.push_back(P(pre_i, pre_j));
        path_str += get_path_str(diff_i, diff_j);
        i = pre_i, j = pre_j;
        pre_i = pre[i][j].first, pre_j = pre[i][j].second;
    }
    reverse(path.begin(), path.end());
    reverse(path_str.begin(), path_str.end());

    return path_str;
}

void read_hv(){
  for(int i = 0; i < 30; i++) for(int j = 0; j < 29; j++) cin >> h[i][j];
  for(int i = 0; i < 29; i++) for(int j = 0; j < 30; j++) cin >> v[i][j];
}
void read_st(){
  cin >> si >> sj >> ti >> tj;
}
void read_ae(){
  cin >> a >> e;
}
string generate_path(){
  string path = "";
  dijkstra();

  path = restore();
  return path;
}
int compute_path_length(string path){
  return 10;
}

void update_hv(int prev_result, string path){
  int ci = si, cj = sj;
  double ave_dis = (double)prev_result / path.size();
  int ratio = 7;
  for (int i = 0; i < (int)path.size(); i++)
  {
    char c = path[i];
    if(c=='D'){
      v[ci][cj] = (v[ci][cj]*ratio + ave_dis*(10-ratio))/10;
      ci++;
    }
    if(c=='U'){
      v[ci-1][cj] = (v[ci-1][cj]*ratio + ave_dis*(10-ratio))/10;
      ci--;
    }
    if(c=='R'){
      h[ci][cj] = (h[ci][cj]*ratio + ave_dis*(10-ratio))/10;
      cj++;
    }
    if(c=='L'){
      h[ci][cj-1] = (h[ci][cj-1]*ratio + ave_dis*(10-ratio))/10;
      cj--;
    }
  }
}

int main(int argc, char *argv[]){
  double init_dis = 4000.0;

  h.assign(30,vector<double>(30, init_dis));
  v.assign(30,vector<double>(30, init_dis));

  bool is_test = false;

  if(is_test) read_hv();

  for (int i = 0; i < 1000; i++)
  {

    read_st();
    if(is_test) read_ae();

    string path = generate_path();
    cout << path << endl;

    int prev_result;
    if(is_test){
      prev_result = compute_path_length(path);
    }
    else{
      cin >> prev_result;
      update_hv(prev_result, path);
    }
  }

  return 0;
}