#include<bits/stdc++.h>
using namespace std;

#define   fi(a,b) for(int i=a;i<b;i++)
#define   fj(a,b) for(int j=a;j<b;j++)
#define   ff first
#define   ss second
#define   ll long long
#define   ld long double
#define   ull unsigned long long
#define   bp(x) __builtin_popcount(x)
#define   pr(x) for(auto it: x) cout<<it<<" "; cout<<endl;
#define   getMax(x) max_element(x.begin(),x.end())
#define   getMin(x) min_element(x.begin(),x.end())
#define   endl "\n"
typedef   vector<int> vi;
typedef   vector< pair<int,int> > vii;
typedef   vector<long long> vl;
typedef   pair<int,int> pii;
typedef   pair<ll,ll> pll;
typedef   vector< pair<ll,ll> > vll;
//int dx[]={1,0,-1,0};
//int dy[]={0,1,0,-1};
//int dx[]={-1,0,1,1,1,0,-1,-1};
//int dy[]={-1,-1,-1,0,1,1,1,0};

//Time Complexity - O(log(n)log(m))
struct FenwickTree {
    vector<ll> bit;  // binary indexed tree
    int n;

    FenwickTree(int n) {
        this->n = n;
        bit.assign(n, 0);
    }

    ll sum(int r) {
        ll ret = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1)
            ret += bit[r];
        return ret;
    }

    ll sum(int l, int r) {
        return sum(r) - sum(l - 1);
    }

    void upd(int idx, int delta) {
        for (; idx < n; idx = idx | (idx + 1))
            bit[idx] += delta;
    }
};



void nikal_pehli_fursat_mai(){
    ll n, m, q;
    cin>>n>>m>>q;
    vector<array<ll, 3>>qry(q);
    map<ll, ll>id;
    int cnt = 0;
    vl a(n), b(m);
    fi(0, q){
    	fj(0, 3) cin>>qry[i][j];
    	id[qry[i][2]];
    }
    id[0];
    for(auto it: id) id[it.ff] = cnt++;
	FenwickTree fa1(cnt+10), fa2(cnt+10), fb1(cnt+10), fb2(cnt+10);
    ll ans = 0;
    fa1.upd(0, n);
    fb1.upd(0, m);
    fi(0, q){
    	ll t = qry[i][0], x = qry[i][1], y = qry[i][2];
    	x--;
    	if(t==1){
    		ll curr = a[x];
    		ans -= fb1.sum(0, id[curr])*curr;
    		ans -= fb2.sum(id[curr]+1, cnt+5);
    		ans += fb1.sum(0, id[y])*y;
    		ans += fb2.sum(id[y]+1, cnt+5);
    		fa1.upd(id[curr], -1);
    		fa1.upd(id[y], 1);
    		fa2.upd(id[curr], -curr);
    		fa2.upd(id[y], y);
    		a[x] = y;
    	}
    	else{
    		ll curr = b[x];
    		ans -= fa1.sum(0, id[curr])*curr;
    		ans -= fa2.sum(id[curr]+1, cnt+5);
    		ans += fa1.sum(0, id[y])*y;
    		ans += fa2.sum(id[y]+1, cnt+5);
    		fb1.upd(id[curr], -1);
    		fb1.upd(id[y], 1);
    		fb2.upd(id[curr], -curr);
    		fb2.upd(id[y], y);
    		b[x] = y;
    	}
    	cout<<ans<<endl;
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1; 
    // cin>>tc;
    while(tc--){
    nikal_pehli_fursat_mai();
    }
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.14;
void solve(){
    int x, y, a, b;
    cin >> x >> y >> a >> b;
    int cnt = 0;
    while(1){
        if(y / a < x)break;
        if(a * x >= y)break;
        if(a * x >= b + x)break;
        x *= a;
        cnt++;
    }
    cnt += (y - x - 1) / b;
    cout << cnt << "\n";
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}