#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

// 1-indexed
template<typename T>
struct BIT{
    int n;
    vector<T> bit;
    BIT(int n_=0):n(n_),bit(n+1){}
    T sum(int i){
        T res=0;
        for(;i>0;i-=(i&-i))res+=bit[i];
        return res;
    }
    T sum(int l,int r){
        if(l>r)return 0;
        return sum(r)-sum(l-1);
    }
    void add(int i,T a){
        if(i==0)return;
        for(;i<=n;i+=(i&-i)){bit[i]+=a;}
    }
    int lower_bound(T k){ // k<=sum(res)
        if(k<=0)return 0;
        int res=0,i=1;
        while((i<<1)<=n)i<<=1;
        for(;i;i>>=1){
            if(res+i<=n&&bit[res+i]<k)k-=bit[res+=i];
        }
        return res+1;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    int q; cin >> q;
    vector<ll> v={0};
    vector<int> t(q),x(q),y(q);
    for(int i=0;i<q;i++){
        cin >> t[i] >> x[i] >> y[i];
        x[i]--;
        v.push_back(y[i]);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    int K=v.size();
    BIT<int> bit1(K+1),bit2(K+1);
    BIT<ll> sum1(K+1),sum2(K+1);
    ll res=0;
    bit1.add(1,n);
    bit2.add(1,m);
    vector<int> a(n,1),b(m,1);
    auto getid=[&](int u)->int{
        return lower_bound(v.begin(), v.end(),u)-v.begin()+1;
    };
    for(int i=0;i<q;i++){
        if(t[i]==1){
            int id=a[x[i]];
            res-=sum2.sum(id,K);
            res-=v[id-1]*bit2.sum(id-1);
            bit1.add(id,-1);
            sum1.add(id,-v[id-1]);

            id=getid(y[i]);
            a[x[i]]=id;
            res+=sum2.sum(id+1,K);
            res+=v[id-1]*bit2.sum(id);
            bit1.add(id,1);
            sum1.add(id,v[id-1]);
        }
        else{
            int id=b[x[i]];
            res-=sum1.sum(id+1,K);
            res-=v[id-1]*bit1.sum(id);
            bit2.add(id,-1);
            sum2.add(id,-v[id-1]);

            id=getid(y[i]);
            b[x[i]]=id;
            res+=sum1.sum(id+1,K);
            res+=v[id-1]*bit1.sum(id);
            bit2.add(id,1);
            sum2.add(id,v[id-1]);
        }
        cout << res << "\n";
    }
}


#include "bits/stdc++.h"
#include<sstream>
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const long long inf = 1e18;
const ll INFL = 1e18;
const ll MOD = 1e9 + 7;

int digit(ll x) {
    int digits = 0;
 
    while(x > 0){
        x /= 10;
        digits++;
    }
 
    return digits;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}
 
bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
long long modpow(long long a, long long b, long long m){
    long long ans = 1;
    while(b > 0){
        if (b % 2 == 1){
            ans *= a;
            ans %= m;
        }
        a *= a;
        a %= m;
        b /= 2;
    }
    return ans;
}

long long comb(long long x, long long y){
    int z;
    if (y == 0) return 1;
    else {
        z = modpow(x, y/2, MOD)*modpow(x, y/2, MOD)%MOD;
        if (y % 2 == 1) z = z*x%MOD;
        return z;
    }
}


vector<pair<long long, long long>> prime_fact(long long x){
    vector<pair<long long, long long>> res;
    for(int i = 2;i*i <= x;i++){
        if (x % i == 0){
            long long cnt = 0;
            while(x % i == 0){
                cnt++;
                x /= i;
            }
            res.push_back({i, cnt});
        }
    }
    if (x != 1){
        res.push_back({x, 1});
    }
    return res;
}

int64_t mod_inv(int64_t a, int64_t m){
    int64_t b = m, u = 1, v = 0;

    while(b){
        int64_t t = a/b;
        a -= t*b;
        swap(a, b);
        u -= t*v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;

    return u;
}


// {g, x, y}: ax + by = g
tuple<long long, long long, long long> extgcd(long long a, long long b){
    if (b == 0) return {a, 1, 0};
    long long g, x, y;
    tie(g, x, y) = extgcd(b, a % b);
    return {g, y, x - a/b*y};
}

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

//////////////////////////

long long score(vector<long long> cnt){
    long long ans = 0;
    for(int i = 1;i <= 9;i++){
        long long res = i;
        for(int j = 0;j < cnt[i];j++){
            res *= 10;
        }
        ans += res;
    }
    return ans;
}

int main(){
    long long k;
    string s, t;
    cin >> k >> s >> t;
    vector<long long> aoki(10, 0), taka(10, 0), card(10, k);
    for(int i = 0;i < 4;i++){
        int a = int(s[i] - '0');
        int b = int(t[i] - '0');
        taka[a]++;
        aoki[b]++;
        card[a]--;
        card[b]--;
    }

    long long win = 0;
    for(int i = 1;i < 10;i++){
        aoki[i]++;
        for(int j = 1;j < 10;j++){
            taka[j]++;
            if (score(taka) > score(aoki)){
                win += card[i]*(card[j] - (i == j));
            }
            taka[j]--;
        }
        aoki[i]--;
    }
    long long r = 9*k - 8;
    cout << (double(win) / r) / (r - 1) << endl;
}

