#include<bits/stdc++.h>
//=====================START-MACRO=====================
namespace gengar
{
	#pragma GCC optimize("Ofast")
	using namespace std;
	namespace TypeDef
	{
		#define int long long
		#define itn int
		#define uint unsigned long long
		using Int=int64_t;
		using uInt=uint64_t;
		#define ld long double
		#define P pair<int,int>
		#define vt(tp) vector<tp>
		#define vvt(nm,tp,h,w,n) vector<vector<tp>>nm((h),vector<tp>(w,n))
		#define vvp vector<vector<P>>
		#define hmap unordered_map
		#define hset unordered_set
		#define PQ priority_queue
	};
	namespace OthDef
	{
		#define all(x) x.begin(),x.end()
		#define nsort(x) sort(all(x))
		#define rsort(x) nsort(x);reverse(all(x))
		#define unq(v) v.erase(unique(all(v)),v.end())
		#define l_b(c,x) distance(c.begin(),lower_bound(all(c),(x)))
		#define u_b(c,x) distance(c.begin(),upper_bound(all(c),(x)))
		#define fi first
		#define se second
		#define mp make_pair
		#define pb push_back
		#define eb emplace_back
		#define spc ' '
		#define pass 
		void CIN(){}
		template<typename Car,typename... Cdr>
		void CIN(Car&&car,Cdr&&...cdr){cin>>car;CIN(forward<Cdr>(cdr)...);}
		template<class T>void drop(T x){cout<<(x)<<endl;exit(0);}
		void dYes(){puts("Yes");exit(0);}
		void dNo(){puts("No");exit(0);}
		#define Bit(n) (1LL<<(n))
		#define Bitall(n,i) for(int bit=0;bit<(1<<(int)(n));bit++)for(int i=0;i<(int)(n);i++)
		#define Bitif(i) if(bit&(1<<i))
	};
	namespace RepDef
	{
		#define _overload3(_1,_2,_3,name,...) name
		#define _rep(i,n) repi(i,0,n)
		#define repi(i,a,b) for(int i=(a),__SIZE##_=(b);i<__SIZE##_;i++)
		#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
		#define rrep(i,n) for(int i=1,__SIZE##_=(n);i<__SIZE##_;i++)
		#define repp(i,n) for(int i=0,__SIZE##_=(n);i<=__SIZE##_;i++)
		#define per(i,n) for(int i=(n)-1;i>=0;i--)
		#define pper(i,n) for(int i=(n)-1;i>=1;i--)
		#define perr(i,n) for(int i=(n);i>=0;i--)
	};
	namespace MathDef
	{
		const int inf=Bit(60);
		const int pi=acos(-1);
		const int mod=1000000007;//998244353
		#define myceil(a,b) ((a)+((b)-1))/(b)
		#define scale(n) cout<<fixed<<setprecision(n)
		int gcd(int a,int b){return b?gcd(b,a%b):a;}
		int lcm(int a,int b){return a/gcd(a,b)*b;}
		int fact(int n){int f=n;pper(i,n){f*=i;f%=mod;}return f;}
		template<class T>int chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
		template<class T>int chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
	};
	namespace AllDef
	{
		using namespace TypeDef;
		using namespace OthDef;
		using namespace RepDef;
		using namespace MathDef;
	};
	using namespace AllDef;
};
using namespace gengar;

//=======================END-MACRO=======================

namespace AHC001
{

//=====================START-AHC001======================

double dst(double a,double b,double c,double d)
{
	double ret=sqrt(pow(double(c)-double(a),2)+pow(double(d)-double(b),2));
	return ret/2/sqrt(2);
}

void solve()
{
	int n;cin>>n;
	vector<double>a(n),b(n),r(n);
	rep(i,n)cin>>a[i]>>b[i]>>r[i];
	double dist[200];
	rep(i,200)dist[i]=inf;
	//ここまで入力とか
	//dist計算
	rep(i,n)for(int j=0;j<n;j++)
	{
		if(j==i)continue;
		chmin(dist[i],dst(a[i],b[i],a[j],b[j]));
	}
	
	rep(i,n)
	{
		double lpdist=dist[i];
		if(dist[i]*dist[i]>r[i]/4)lpdist=(sqrt(r[i]))/2;
		cout<<(int)(max(a[i]-lpdist+0.5,0.0))<<spc;
		cout<<(int)(max(b[i]-lpdist+0.5,0.0))<<spc;
		cout<<(int)(min(a[i]+lpdist+0.5,10000.0))<<spc;
		cout<<(int)(min(b[i]+lpdist+0.5,10000.0))<<endl;
	}
	exit(0);
}

//=====================END-AHC001======================
};

using namespace AHC001;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

namespace IO {
  char buf[1000000], *p1 = buf, *p2 = buf;
  inline char gc() {
    if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
    return p1 == p2 ? EOF : *(p1++);
  }
  template <class T> inline void read(T &n) {
    n = 0; RI ch = gc(), f;
    while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
    f = (ch == '-' ? ch = gc(), -1 : 1);
    while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
    n *= f;
  }
  char Of[105], *O1 = Of, *O2 = Of;
  template <class T> inline void print(T n, char ch = '\n') {
    if (n < 0) putchar('-'), n = -n;
    if (n == 0) putchar('0');
    while (n) *(O1++) = (n % 10) ^ 48, n /= 10;
    while (O1 != O2) putchar(*(--O1));
    putchar(ch);
  }
}

using IO :: read;
using IO :: print;

int const mod = 1e9 + 7;
int f[1005];

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n; cin >> n;
  char AA; cin >> AA;
  char AB; cin >> AB;
  char BA; cin >> BA;
  char BB; cin >> BB;
  f[n - 2] = 1;
  for (RI i = n - 2; i; --i) {
    if (AB == 'A') {
      if (AA == 'B') {
        if (i - 2 >= 0)
          f[i - 2] = (f[i - 2] + f[i]) % mod;
        if (BA == 'B')
          for (RI j = i - 3; j >= 0; --j)
            f[j] = (f[j] + f[i]) % mod;
      }
      f[i - 1] = (f[i - 1] + f[i]) % mod;
    }
    else {
      if (BB == 'A') {
        if (i - 2 >= 0)
          f[i - 2] = (f[i - 2] + f[i]) % mod;
        if (BA == 'A')
          for (RI j = i - 3; j >= 0; --j)
            f[j] = (f[j] + f[i]) % mod;
      }
      f[i - 1] = (f[i - 1] + f[i]) % mod;
    }
  }
  cout << f[0] << endl;

  return 0;
}

// created by Daniel yuan
/*
     ________
    /        \
   / /      \ \
  / /        \ \
  \            /
   \  ______  /
    \________/
*/
