#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define REP(i,a,b) for(int i = (a); i < (b); i++)
#define MOD 1000000007

int main(void) {
  ll k;
  cin >> k;
  string s,t;
  cin >> s >> t;
  ll taka=0,aoki=0;
  vector<int> cnt_taka(10,0),cnt_aoki(10,0);
  rep(i,4) cnt_taka[s[i]-'0']++;
  rep(i,4) cnt_aoki[t[i]-'0']++;
  rep(i,10) taka+=i*pow(10,cnt_taka[i]);
  rep(i,10) aoki+=i*pow(10,cnt_aoki[i]);
  //rep(i,10) printf("cnt_taka[%d]==%d\n",i,cnt_taka[i]);
  //rep(i,10) printf("cnt_aoki[%d]==%d\n",i,cnt_aoki[i]);
  //# patern
  ll tmp_t=taka,tmp_a=aoki;
  ll ans=0;
  rep2(i,1,10) {
    rep2(j,1,10) {
      tmp_t=taka,tmp_a=aoki;
      tmp_t+=i*pow(10,cnt_taka[i])*9;
      tmp_a+=j*pow(10,cnt_aoki[j])*9;
      //taka win
      if(tmp_a<tmp_t) {
        ll a,b;
        a=k-cnt_taka[i]-cnt_aoki[i];
        b=k-cnt_taka[j]-cnt_aoki[j];
        if(i==j) b--;
        if(a>0&&b>0) ans+=a*b;
        //printf("ans=%d i=%d j=%d\n",ans,i,j);
      }
    }
  }
  //cout << ans << endl;
  double res;
  res=(double)ans/((9*k-4*2)*(9*k-4*2-1));
  //cout << res << endl;
  printf("%.8lf\n",res);
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
const int INF = 1001001001;
const int BASE = 10000;

int main() {
  int n;
  cin >> n;
  vector<tuple<int, int, int>> input(n);
  map<tuple<int, int>, int> mp;
  rep(i, n) {
    int x, y, c;
    cin >> x >> y >> c;
    input.at(i) = {x, y, c};
    mp[{x, y}] = i;
  }
  
  // FILE *fp;
  // fp = fopen("out.txt", "w");
  
  vector<tuple<int, int, int, int>> ans(n);
  set<tuple<int, int, int, int>> se;
  int co = 0;
  rrep(bh, BASE)rrep(bw, BASE) {
    if(mp.find({bw, bh}) == mp.end())  continue;
    int idx = mp[{bw, bh}];
    auto [sx, sy, c] = input.at(idx);
    int ex = BASE, ey = BASE;
    set<pair<int, int>> pse;
    for(auto [px, py, pw, ph] : se) {
      int pex = px + pw, pey = py + ph;
      if(sx < pex && sy < py){
        if(px <= sx) ey = min(ey, py);
        else pse.insert({px, py});
      }
      if(sy < pey && sx < px){
        if(py <= sy) ex = min(ex, px);
        else pse.insert({px, py});
      }
    }
    int mnabs = INF;
    int rh = 1, rw = 1;
    if(idx % 2 == 0) {
      for(int h = 1; sy + h <= ey; h++) {
        for(int w = 1; sx + w <= ex; w++) {
          if(pse.find({sx+w, sy+h}) != pse.end()) {
            ex = sx + w;
          }
          int s = h*w;
          if(abs(c - s) < mnabs) {
            mnabs = abs(c - s);
            rh = h, rw = w;
          }
        }
      }
    } else {
      for(int w = 1; sx + w <= ex; w++) {
        for(int h = 1; sy + h <= ey; h++) {
          if(pse.find({sx+w, sy+h}) != pse.end()) {
            ey = sy + h;
          }
          int s = h*w;
          if(abs(c - s) < mnabs) {
            mnabs = abs(c - s);
            rh = h, rw = w;
          }
        }
      }
    }
    se.insert({sx, sy, rw, rh});
    ans.at(idx) = {sx, sy, sx+rw, sy+rh};
  }

  for(auto [a, b, c, d] : ans) {
    // fprintf(fp, "%d %d %d %d\n", a, b, c, d);
    cout << a << " " << b << " " << c << " " << d << endl;
  }
  return 0;
}