#include <iostream>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;
ll INF = 1000000000000000;
struct segment_tree{
    int n; vector<ll> seg;
    segment_tree(vector<ll> v){
        n = v.size(); seg.resize(2*n);
        for(int i=0;i<n;i++) seg[i + n] = v[i];
        for(int i=n - 1;i>0;i--) seg[i] = seg[i<<1] + seg[i<<1|1];
    }
    void update(int p,ll val){
        for(seg[p += n] += val;p>1;p>>=1) seg[p>>1] = seg[p] + seg[p^1];
    }
    ll query(int l,int r){
        ll res = 0;
        for(l += n,r += n; l<r;l>>=1,r>>=1){
            if(l&1) res += seg[l++];
            if(r&1) res += seg[--r];
        }
        return res;
    }
    void clear(){for(int i=0;i<2*n;i++) seg[i] = 0;}
};

vector<int> zz,a,b;
map<int,int> mp;
ll t[200010],x[200010],y[200010];
int main(){
    ll i,n,m,q; cin >> n >> m >> q;
    mp[0]++;
    vector<int> a(n),b(m);
    for(i=0;i<q;i++){
        cin >> t[i] >> x[i] >> y[i]; x[i]--;
        mp[y[i]]++;
    }
    for(auto x:mp) zz.push_back(x.first);
    for(i=0;i<zz.size();i++) mp[zz[i]] = i;
    vector<ll> v(zz.size());
    segment_tree seg1(v),seg2(v),seg_num1(v),seg_num2(v);
    for(i=0;i<n;i++) seg1.update(mp[a[i]],a[i]),seg_num1.update(mp[a[i]],1);
    for(i=0;i<m;i++) seg2.update(mp[b[i]],b[i]),seg_num2.update(mp[b[i]],1);
    ll ans = 0;
    int k = v.size();
    for(i=0;i<n;i++) ans += seg_num2.query(0,mp[a[i]])*a[i] + seg2.query(mp[a[i]],k);
    for(i=0;i<q;i++){
        if(t[i]==1){
            int j = x[i];
            ans -= seg_num2.query(0,mp[a[j]])*a[j] + seg2.query(mp[a[j]],k);
            seg1.update(mp[a[j]],-a[j]); seg_num1.update(mp[a[j]],-1);
            a[j] = y[i];
            seg1.update(mp[a[j]],a[j]); seg_num1.update(mp[a[j]],1);
            ans += seg_num2.query(0,mp[a[j]])*a[j] + seg2.query(mp[a[j]],k);
        }
        if(t[i]==2){
            int j = x[i];
            ans -= seg_num1.query(0,mp[b[j]])*b[j] + seg1.query(mp[b[j]],k);
            seg2.update(mp[b[j]],-b[j]); seg_num2.update(mp[b[j]],-1);
            b[j] = y[i];
            seg2.update(mp[b[j]],b[j]); seg_num2.update(mp[b[j]],1);
            ans += seg_num1.query(0,mp[b[j]])*b[j] + seg1.query(mp[b[j]],k);
        }
        cout << ans << endl;
    }
}
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define pb push_back

int pw(int c)
{
    int res = 1;
    if (c == 0)
        return 1;
    while (c-- > 0)
        res *= 10;
    return res;
}

int sc(vector<int> &st, int last)
{
    int res = 0;
    st[last]++;
    for (int i = 1; i < 10; i++)
        res += i * pw(st[i]);
    st[last]--;
    return res;
}

double solve()
{
    int k;
    string s, t;
    cin >> k >> s >> t;
    vector<int> cnt(10, k), bag(10, k), st1(10), st2(10);
    for (int i = 0; i < 4; i++)
    {
        cnt[s[i] - '0']--;
        cnt[t[i] - '0']--;
        st1[s[i] - '0']++;
        st2[t[i] - '0']++;
    }
    for (int i = 1; i <= 9; i++)
        bag[i] = cnt[i];
    ll w1 = 0, w2 = 0;
    for (int i = 1; i <= 9; i++)
    {
        if (cnt[i] == 0)
            continue;
        ll w = cnt[i];
        cnt[i]--;
        for (int j = 1; j <= 9; j++)
        {
            if (cnt[j] == 0)
                continue;
            if (sc(st1, i) > sc(st2, j))
                w1 += w * 1ll * cnt[j];
            else
                w2 += w * 1ll * cnt[j];
        }
        cnt[i]++;
    }
    return w1 * 1.0 / (w1 + w2) * 1.0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << setprecision(18) << fixed << solve() << "\n";
    return 0;
}