#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
#define per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i))
#define gg 9223372036854775807
#ifdef LOCAL
#define debug(x) cerr<<__LINE__<<": "<<#x<<"="<<x<<endl;
#define debugALL(x) cerr<<__LINE__<<": "<<#x<<"=";for(auto i=(x).begin();i!=--(x).end();i++)cerr<<*i<<" ";cerr<<*--(x).end()<<endl;
#else
#define debug(x) true
#define debugALL(x) true
#endif
using namespace std;

template<typename T>
struct segment_tree{
    function<T(T,T)> f = [](T a, T b){return a+b;};
    T inf=0;
    vector<T> value;
    int N;
    segment_tree(int n){
        N=1;
        while(N<n)N*=2;
        value.assign(2*N-1,inf);
    }
    segment_tree(int n, function<T(T,T)> func, T t1){
        N=1;
        while(N<n)N*=2;
        value.assign(2*N-1,t1);
        f=func;
        inf=t1;
    }
    void update(int i,T x){
        i+=N-1;
        value[i]=x;
        while(i>0){
            i=(i-1)/2;
            value[i]=f(value[i*2+1],value[i*2+2]);
        }
    }
    T query(T a,T b){
        return query(a,b,0,0,N);
    }
    T query(T a,T b, int k, int l, int r){
        if(r<=a || b<=l)return inf;
        if(a<=l && r<=b){
            return value[k];
        }else{
            ll c1=query(a,b,2*k+1,l,(l+r)/2);
            ll c2=query(a,b,2*k+2,(l+r)/2,r);
            return f(c1,c2);
        }
    }
    void print(){
        for(int i=0;i<ceil(log2(N))+1;i++){
            for(int j=0;j<(1<<i);j++){
                cout<<value[j+(1<<i)-1]<<((j==(1<<i)-1)?';':',');
            }
            cout<<endl;
        }
    }
};

V tmp;
int get(ll val){
    return lower_bound(tmp.begin(),tmp.end(),val)-tmp.begin();
}

int main(){
    ll n,m,q;
    cin>>n>>m>>q;
    V t(q),x(q),y(q);
    rep(i,q){
        cin>>t[i]>>x[i]>>y[i];
        x[i]--;
    }
    tmp=y;
    tmp.push_back(0);
    sort(tmp.begin(),tmp.end());

    segment_tree<ll> sa(3e5);
    segment_tree<ll> sb(3e5);
    sa.update(0,n);
    sb.update(0,m);
    segment_tree<ll> ssa(3e5);
    segment_tree<ll> ssb(3e5);
    ssa.update(0,0);
    ssb.update(0,0);
    V a(n,0),b(m,0);
    ll ans=0;
    rep(i,q){
        if(t[i]==1){
            ll nowvalid=get(a[x[i]]);
            ll pval=a[x[i]];
            ll prev=sb.query(0,nowvalid);
            ll pprev=ssb.query(0,nowvalid);
            sa.update(nowvalid,sa.query(nowvalid,nowvalid+1)-1);
            ssa.update(nowvalid,ssa.query(nowvalid,nowvalid+1)-a[x[i]]);
            a[x[i]]=y[i];
            ll nextvalid=get(y[i]);
            ll next=sb.query(0,nextvalid);
            ll nnext=ssb.query(0,nextvalid);
            sa.update(nextvalid,sa.query(nextvalid,nextvalid+1)+1);
            ssa.update(nextvalid,ssa.query(nextvalid,nextvalid+1)+a[x[i]]);
            ans+=a[x[i]]*next-prev*pval-(nnext-pprev);
        }else{
            ll nowvalid=get(b[x[i]]);
            ll pval=b[x[i]];
            ll prev=sa.query(0,nowvalid);
            ll pprev=ssa.query(0,nowvalid);
            sb.update(nowvalid,sb.query(nowvalid,nowvalid+1)-1);
            ssb.update(nowvalid,ssb.query(nowvalid,nowvalid+1)-b[x[i]]);
            b[x[i]]=y[i];
            ll nextvalid=get(y[i]);
            ll next=sa.query(0,nextvalid);
            ll nnext=ssa.query(0,nextvalid);
            sb.update(nextvalid,sb.query(nextvalid,nextvalid+1)+1);
            ssb.update(nextvalid,ssb.query(nextvalid,nextvalid+1)+b[x[i]]);
            //ans+=(next-prev)*y[i]+pprev-nnext;
            ans+=b[x[i]]*next-prev*pval-(nnext-pprev);
        }
        cout<<ans<<endl;
    }
}

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

const int N = 100 + 1;
const int K = 1'000'000;

int mod;

int add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
  return a;
}

int sub(int &a, int b) {
  a -= b;
  if (a < 0) {
    a += mod;
  }
  return a;
}

int mul(int a, int b) {
  return (long long) a * b % mod;
}

int ways[N][K];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m >> mod;

  ways[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < K; ++j) {
      int prv = j - i;
      int prv_prv = j - i * (m + 1);

      ways[i][j] = ways[i - 1][j];
      if (prv >= 0) {
        add(ways[i][j], ways[i][prv]);
      }
      if (prv_prv >= 0) {
        sub(ways[i][j], ways[i - 1][prv_prv]);
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    int ans = 0;
    for (int j = 0; j < K; ++j) {
      add(ans, mul(ways[i][j], ways[n - i - 1][j]));
    }
    ans = mul(ans, m + 1);
    sub(ans, 1);
    cout << ans << "\n";
  }
}
