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

const int p1 = 998244353, p2 = 469762049, Maxn = 1 << 17 | 5;
int maxn, maxa, mod, rev[Maxn];
int tot, l[Maxn];
const long long lcm = p1 * (long long) p2;
void get_rev(int len)
{
	for (int i = 0; i < len; i++)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) * (len >> 1));
}
long long fast_pow(long long x, long long y, int p)
{
	long long ans = 1, now = x;
	while (y)
	{
		if (y & 1) ans = ans * now % p;
		now = now * now % p;
		y >>= 1;
	}
	return ans;
}
void NTT(int now[], int len, int p, bool type = false)
{
	l[0] = 1;
	int inv3 = fast_pow(3, p - 2, p);
	for (int i = 0; i < len; i++)
		if (i < rev[i]) swap(now[i], now[rev[i]]);
	for (int i = 1; i < len; i <<= 1)
	{
		long long w = fast_pow(type ? inv3 : 3, (p - 1) / (i << 1), p);
		for (int j = 1; j < i; j++)
			l[j] = l[j - 1] * w % p;
		for (int j = 0; j < len; j += (i << 1))
			for (int k = j; k < i + j; k++)
			{
				int x = now[i + k] * (long long) l[k - j] % p, y = now[k];
				now[k] = (x + y) % p;
				now[i + k] = (y - x + p) % p;
			}
	}
	if (type)
	{
		long long inv = fast_pow(len, p - 2, p);
		for (int i = 0; i < len; i++)
			now[i] = now[i] * inv % p;
	}
}
void multi(int x[], int y[], int result[], int len, int p)
{
	NTT(x, len, p), NTT(y, len, p);
	for (int i = 0; i < len; i++)
		result[i] = x[i] * (long long) y[i] % p;
	NTT(result, len, p, true);
}
long long mul(long long x, long long y)
{
	return ((unsigned long long) x * y - (long long) (x / (long double) lcm * y) * lcm + lcm) % lcm;
}
void multi(int x[], int y[], int result[], int len)
{
	get_rev(len);
	static int tmp1[Maxn], tmp2[Maxn], tmpx[Maxn], tmpy[Maxn];
	for (int i = 0; i < len; i++)
		tmpx[i] = x[i], tmpy[i] = y[i];
	multi(tmpx, tmpy, tmp1, len, p1);
	for (int i = 0; i < len; i++)
		tmpx[i] = x[i], tmpy[i] = y[i];
	multi(tmpx, tmpy, tmp2, len, p2);
	long long P1 = fast_pow(p2, p1 - 2, p1), P2 = fast_pow(p1, p2 - 2, p2);
	for (int i = 0; i < len; i++)
		result[i] = (mul(mul(tmp1[i], p2), P1) + mul(mul(tmp2[i], p1), P2)) % lcm % mod;
}
void poly_pow(int y, int len)
{
	int now = 0;
	static int ans[2][Maxn];
	memset(ans[0], 0, sizeof(int[len << 1]));
	memset(ans[1], 0, sizeof(int[len << 1]));
	static int tmp[Maxn], result[2][Maxn];
	for (int j = 30; j >= 0; j--)
	{
		cerr << j << endl;
		memset(tmp, 0, sizeof(int[len << 1]));
		for (int i = 0; i < len; i++)
			tmp[i] = (ans[0][i] + ans[1][i]) % mod;
		tmp[0]++;
		for (int p = 0; p <= 1; p++)
			multi(tmp, ans[(now & 1) ^ p], result[p], len << 1);
		for (int p = 0; p <= 1; p++)
			for (int i = 0; i < len; i++)
				(ans[p][i] += result[p][i]) %= mod;
		now <<= 1;
		if (y & (1 << j))
		{
			for (int i = len - 1; i; i--)
				(ans[1][i] += ans[0][i - 1] + ans[1][i - 1]) %= mod;
			ans[1][1]++;
			now++;
		}
		if (now != y)
			for (int i = 1; i <= maxn; i += 2)
				(tot += ans[1][i]) %= mod;
	}
}
int lower(int x)
{
	int tmp = 1;
	for (; tmp < x; tmp <<= 1);
	return tmp;
}
int main()
{
	scanf("%d%d%d", &maxn, &maxa, &mod);
	poly_pow(maxa, lower(maxn + 1));
	printf("%d", tot);
	return 0;
}


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

typedef unsigned long long ullong;

ullong my_sqrt(ullong k) {
    ullong low = 1, high = k;
    while (low <= high) {
        ullong mid = low + ((high - low) >> 1);
        if (mid * mid > k)
            high = mid - 1;
        else if (mid * mid < k)
            low = mid + 1;
        else
            return mid;
    }
    return high;
}

int main() {
    ullong n;
    scanf("%llu", &n);
    if (n % 3) {
        puts("0");
        return 0;
    }
    n /= 3;
    ullong res = 0;
    for (ullong x = 2; x * x * x <= n; ++x) {
        if (n % x)
            continue;
        ullong nx = n / x;
        ullong sqrt_nx = my_sqrt(nx);
        for (ullong y = sqrt_nx; y >= x; --y) {
            if (nx % y)
                continue;
            ullong z = nx / y;
            ullong sum = x + y + z;
            if (sum <= z << 1)
                break;
            if (sum & 1)
                continue;
            if (x == y && y == z)
                ++res;
            else if (x == y || y == z || z == x)
                res += 3;
            else
                res += 6;
        }
    }
    printf("%llu", res);
}


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

using Poly = vector<int>;

const int P = 998244353;

Poly operator+(Poly lhs, Poly rhs) {
	Poly ret(max(lhs.size(), rhs.size()), 0);
	for (int i = 0; i < ret.size(); i++) ret[i] = ((i < lhs.size() ? lhs[i] : 0) + (i < rhs.size() ? rhs[i] : 0)) % P;
	return ret;
}

Poly operator-(Poly lhs, Poly rhs) {
	Poly ret(max(lhs.size(), rhs.size()), 0);
	for (int i = 0; i < ret.size(); i++) ret[i] = ((i < lhs.size() ? lhs[i] : 0) + (i < rhs.size() ? P - rhs[i] : 0)) % P;
	return ret;
}

Poly operator*(Poly lhs, Poly rhs) {
	Poly ret(max(0, (int)(lhs.size() + rhs.size()) - 1), 0);
	for (int i = 0; i < lhs.size(); i++) {
		for (int j = 0; j < rhs.size(); j++) {
			ret[i+j] = (ret[i+j] + lhs[i] * 1LL * rhs[j]) % P;
		}
	}
	return ret;
}

Poly operator*(Poly lhs, int rhs) {
	for (int &x : lhs) x = x * 1LL * rhs % P;
	return lhs;
}

Poly s(Poly p, int k) {
	Poly q(k, 0); p.insert(p.begin(), q.begin(), q.end());
	return p;
}

Poly dot(Poly p) {
	for (int i = 0; i < p.size(); i++) p[i] = 1LL * i * p[i] % P;
	return p;
}

int calc(Poly &a) {
	reverse(a.begin(), a.end());
	int ret = 0;
	while (!a.empty() && !a.back()) a.pop_back(), ret++;
	reverse(a.begin(), a.end());
	return ret;
}

int solve(Poly a, Poly b, int n) {
	n -= calc(a) - calc(b);
	if (n < 0) return 0;
	vector<int> c(n + 1, 0);
	for (int i = 0; i <= n; i++) {
		c[i] = i < a.size() ? a[i] : 0;
		for (int j = 1; j < b.size() && j <= i; j++) c[i] = (c[i] + (P - c[i - j]) * 1LL * b[j]) % P;
	}
	return c[n];
}

int main() {
	int n; cin >> n;
	Poly A = {1, 0, P-1, 0, P-1}, B = dot(A), C = dot(B);
	Poly F0 = B * B * 2 - C * A, F1 = F0 + A * A - B * A * 2, F2 = F1 + A * A * 3 - B * A * 2;
	F0 = A * A * A - s(F0, 1), F1 = s(F1, 2), F2 = A * A * A - s(F2, 3);
	Poly F = F0 * F2 - F1 * F1;
	cout << (solve(B, A, n) * 6LL + P - solve(dot(F), F, n)) % P << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int INF = INT_MAX / 2;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> graph(n);
  vector<vector<int>> rgraph(n);
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    graph[v].emplace_back(u);
    rgraph[u].emplace_back(v);
  }
  int k;
  cin >> k;
  vector<int> path(k);
  for (auto &e : path) {
    cin >> e;
    e--;
  }
  int s = path[0];
  int f = path.back();
  vector<int> dist(n, INF);
  vector<int> cnt(n, 0);
  dist[f] = 0;
  cnt[f] = 0;
  set<pair<int, int>> q;
  q.emplace(0, f);
  while (!q.empty()) {
    auto v = q.begin()->second;
    q.erase(q.begin());
    for (auto u : rgraph[v]) {
      if (dist[u] > dist[v] + 1) {
        dist[u] = dist[v] + 1;
        cnt[u] = 0;
        q.emplace(dist[u], u);
      } else if (dist[u] == dist[v] + 1 && cnt[u] == 0) {
        cnt[u] ++;
        q.emplace(dist[u], u);
      }
    }
  }
  int ans_mn = 0;
  int ans_mx = 0;
  for (int i = 0; i < k - 1; i++) {
    if (dist[path[i]] != dist[path[i + 1]] + 1) {
      ans_mn++;
      ans_mx++;
    } else if (cnt[path[i]]) {
      ans_mx++;
    }
  }
  assert(ans_mn <= ans_mx);
  cout << ans_mn << ' ' << ans_mx;
  return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
using namespace std;
long long kol1, l, tekres, ee, kol, r, n, k, p, e, c, a, b, f,m;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d%d%d", &n, &m, &k);
	scanf("%d%d", &a, &b);
	long long res = 0;
	long long a1 = (a+m*k-1) / (m*k), b1 = (b+m*k-1) / (m*k);
	long long a2 = (a-(a1-1)*(m*k)+k-1) / k, b2 = (b - (b1 - 1)*(m*k) + k - 1) / k;
	if (a1 == b1 && a2 == b2)
	{
		printf("0");
		return 0;
	}
	if (a1 == b1)
	{
		printf("%d", min(10 + abs(a2 - b2), abs(a2 - b2) * 5));
		return 0;
	}
	res += min(10 + a2 - 1, 5 * (a2 - 1));
	res += min(abs(b1 - a1) * 15, (n - max(a1, b1) + min(a1, b1))*15);
	res += min(10 + b2 - 1, 5 * (b2 - 1));
	printf("%d", res);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
bool SR(int &x){return scanf("%d",&x)==1;}bool SR(ll &x){return scanf("%lld",&x)==1;}
bool SR(double &x){return scanf("%lf",&x)==1;}bool SR(char *s){return scanf("%s",s)==1;}
bool RI(){return 1;}
template<typename I,typename... T>
bool RI(I &x,T&... tail){return SR(x)&&RI(tail...);}
#ifndef darry140
#define debug(...)
#else
#define debug(...) do{\
	fprintf(stderr,"%s - %d : ",__PRETTY_FUNCTION__,__LINE__);\
	_DO(__VA_ARGS__);}while(0)
void _DO(){}
template<typename I,typename... T>
void _DO(I&& x,T&&... tail){cerr<<x<<" \n"[sizeof...(tail)==0];_DO(tail...);}
#endif
#define ALL(x) (x).begin(),(x).end()
#define REP1(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define SZ(x) ((int)(x).size())
#define pb push_back
//}}}
inline ll bas(const int &i)
{
	if(i==0) return 60;
	else if(i==1) return 300;
	else
	{
		ll ans=15*pow(10,i)-50;
		while(ans%100) ans++;
		return ans;
	}
}
ll n;
vector<ll> v;
void read()
{
	RI(n);
	int t[2]={0,1};
	REP(i,60)
	{
		if(n%10==t[0]) v.pb(i);
		swap(t[0],t[1]);
		t[0]+=t[1];t[0]%=10;
	}
}
ll mul(ll a,ll b,ll mod)
{
	if(b==0) return 0;
	ll tmp=mul(a,b/16,mod);
	tmp=(tmp*16)%mod;
	return (tmp+a*(b&15))%mod;
}
array<array<ll,2>,2> powmod(ll x,ll MOD)
{
	if(x==0) return {array<ll,2>{1LL,0LL},array<ll,2>{0LL,1LL}};
	auto tmp=powmod(x/2,MOD);
	auto c=tmp;REP(i,2) REP(j,2) c[i][j]=0;
	REP(i,2) REP(j,2) REP(k,2) c[i][j]+=mul(tmp[i][k],tmp[k][j],MOD);
	REP(i,2) REP(j,2) c[i][j]%=MOD;
	if(x&1)
	{
		auto d=tmp;REP(i,2) REP(j,2) d[i][j]=0;
		tmp={array<ll,2>{0LL,1LL},array<ll,2>{1LL,1LL}};
		REP(i,2) REP(j,2) REP(k,2) d[i][j]+=mul(tmp[i][k],c[k][j],MOD);
		REP(i,2) REP(j,2) d[i][j]%=MOD;
		return d;
	}
	return c;
}
bool chk(ll id,ll MOD)
{
	auto A=powmod(id,MOD);
	return A[1][0]%MOD==n%MOD;
}
void build()
{
	vector<ll> pw(13);
	pw[0]=10;
	REP1(i,1,12) pw[i]=pw[i-1]*10;
	REP1(r,1,12)
	{
		ll BAS=bas(r),BM=bas(r-1);
		ll div=BAS/BM;
		vector<ll> cur(div*SZ(v));
		REP(i,div) REP(j,SZ(v))
			cur[i*SZ(v)+j]=v[j]+i*BM;
		v.clear();
		for(ll x:cur) if(chk(x,pw[r]))
			v.pb(x);
	}
}
void sol()
{
	if(SZ(v)) printf("%lld\n",v[0]);
	else puts("-1");
}
int main()
{
	read();
	build();
	sol();
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int n,k,p;
int fpow(int a,int b)
{
	int ans=1,t=a;
	while(b)
	{
		if(b&1)ans=1ll*ans*t%p;
		t=1ll*t*t%p;b>>=1;
	}
	return ans;
}
int lowbit(int x)
{
	return x&(-x);
}
int f[26][250010];
int fac[250010],inv[250010];
void init()
{
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=1ll*fac[i-1]*i%p;
	inv[n]=fpow(fac[n],p-2);
	for(int i=n;i>=1;i--)
		inv[i-1]=1ll*inv[i]*i%p;
	return ;
}
int solve(int cur,int S)
{
	if(f[cur][S]!=-1)
		return f[cur][S];
	if(!S){
		f[cur][S]=fac[n];
		for(int i=1;i<=cur;i++)
			f[cur][S]=1ll*f[cur][S]*(k-i+1)%p;
		return f[cur][S];
	}
	f[cur][S]=0;
	int U=S-lowbit(S);
	for(int T=U;T;T=(T-1)&U)
		f[cur][S]=(f[cur][S]+1ll*inv[S-T]*solve(cur+1,T))%p;
	f[cur][S]=(f[cur][S]+1ll*inv[S]*solve(cur+1,0))%p;
	return f[cur][S];
}
int main()
{
	scanf("%d %d %d",&n,&k,&p);
	int ans=1;
	for(int i=1;i<=n;i++)
		ans=1ll*ans*k%p;
	if(n%2==0){
		init();
		memset(f,-1,sizeof(f));
		ans=(ans-solve(0,n)+p)%p;
	}
	printf("%d\n",ans);
	return 0;
}


/*
गिरते हैं शहसवार ही मैदान-ए-जंग में ।
वो तिफ़्ल क्या गिरे जो घुटनों के बल चले ।।
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int     long long int
#define ull     unsigned int
#define ld      long double
#define pb      push_back
#define pa      pair<int,int>
#define v1d     vector<int>
#define v2d     vector<vector<int> >
#define vpa     vector<pair<int,int>>
#define M       1000000007
#define MN      LLONG_MIN
#define MX      LLONG_MAX
#define ff      first
#define ss      second
#define endl    "\n"
#define v1s     vector<string>
#define all(v)  v.begin(),v.end()
#define S(v)    sort(v.begin(),v.end())
#define RS(v)   sort(v.rbegin(),v.rend())
#define R(v)    reverse(v.begin(),v.end())
#define mxpq(T)    priority_queue <T>
#define mnpq(T)    priority_queue<T,vector<T>,greater<T>>
#define T       int tc;cin>>tc;while(tc--)
#define p2d(v)     for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)      for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)      for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define sz(v)       (int)(v.size())
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define N 400005

void Weapons19(){
    int n,m,a,b,c,d;
    cin>>n>>m>>a>>b>>c>>d;
    if(abs(b-d)>4||abs(c-a)>4)cout<<"Second";
    else if(abs(b-d)==4&&abs(c-a)==3)cout<<"Second";
    else if(abs(b-d)==3&&abs(c-a)==4)cout<<"Second";
    else if(abs(b-d)==4&&abs(c-a)==4)cout<<"Second";
    else cout<<"First";

}

int32_t main(){

    /*
    त्यक्तवाधर्मं च लोभं च
    मोहंचो द्यमास्थिता।
    युद्ध्यध्वमनहंकारा
    यतो धर्मस्ततो जयः।।
    */

    cout<<fixed<<setprecision(16);
    cin.sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    #ifndef ONLINE_JUDGE
     freopen("input.txt",  "r",  stdin);
     freopen("output.txt", "w", stdout);
    #endif

    Weapons19();

}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
int y[27] = { 10010,11020,20011,21012,11011,21021,22022,12021,11011,12012,10120,11130,20121,21122,11121,21131,22132,12131,11121,12122,10221,11231,12113,20222,21223,11222 };
char x[30000];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int t, s, z;
	for (int i = 0; i < 26; i++)
	{
		if (!x[y[i]]) x[y[i]] = i + 'a';
	}
	scanf("%d", &t);
	while (t--)
	{
		z = 0;
		for (int i = 0; i < 5; i++)
			scanf("%d", &s), z = z * 10 + s;
		putchar(x[z]);
	}
	return 0;
}


/*
It was gone before you ever had a chance
lost forever in your disapproving glance

I see your face
it's twisted with shock
falling from grace
you deserve what you got

The ice surrounds you now

You can't pretend
all that you want
I've seen the pain
and all the evil you brought

Quit your fucking crying
and swallow all your pills
your not the only one
with the urge to kill
grab the dusty bottle
and let the liquor spill
devoid of life
death is your final thrill

Bloodshot eyes
can see right through the selfish lies
search forever for a fix that keeps you high

I see your face
it's twisted with shock
falling from grace
you deserve what you got

My hands around your throat

You can't pretend
all that you want
I've seen the pain
and all the evil you brought

I am the king of nothing
over emptiness I reign
drown the sorrow
wash away the pain
*/

//#pragma comment(linker, "/STACK:16777216")
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash

#define  INF 100000000
#define eps 1e-11
//#define M_PI 3.141592653589793
//#define mx 1000000000000ll
#define bs 1000000007
#define bsize 256

using namespace std;

long long n,k,a,b,need;
vector<pair<long long, long long> > v;
vector<long long> v1,v2;
long long ans,alost,rem,todel,cost;

int main(){
//freopen("melman.in","r",stdin);
//freopen("melman.out","w",stdout);
//freopen("C:/input.txt","r",stdin);
//freopen("C:/output.txt","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);

cin>>n>>k;
for (int i=1;i<=n;i++)
{
 cin>>a>>b;
 v.push_back(make_pair(a,b));
}

sort(v.begin(),v.end());
reverse(v.begin(),v.end());

if (k==v.size()+1)need=0;else
need=v[k-1].first;

ans=1e18;

for (int score=need;score<=need+10;score++)
{
 alost=0;
 if (score>n)continue;
 for (int p=0;p<v.size();p++)
 if (v[p].first>score){alost++;}
 rem=k-alost-1;
 if(rem<0)continue;
 v1.clear();
 v2.clear();
 for (int i=0;i<v.size();i++)
 {
  if (v[i].first>score||v[i].first<score-1)v1.push_back(v[i].second);
  else v2.push_back(v[i].second);
 }
 sort(v1.begin(),v1.end());
 sort(v2.begin(),v2.end());
 if (v2.size()>rem)
 {
  todel=v2.size()-rem;
 }
 else todel=0;
 cost=0;
 if (todel>score)continue;
 for (int i=0;i<todel;i++)cost+=v2[i];
 for (int i=todel;i<v2.size();i++)v1.push_back(v2[i]);
 sort(v1.begin(),v1.end());
 for (int i=todel+1;i<=score;i++)
 cost+=v1[i-todel-1];
 ans=min(ans,cost);
}
if (ans>1e16)ans=-1;

cout<<ans<<endl;

cin.get();cin.get();
return 0;}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 7002;

int n, d[N];
ll a[N], b[N];
bool used[N], adj[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> b[i];
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) {
            if (a[i] > (a[i] & a[j])) {
                ++d[i];
                adj[j][i] = true;
            }
        }
    int cur = n;
    while (true) {
        vector<int> v;
        v.clear();
        for (int i = 1; i <= n; ++i)
            if (!used[i] && d[i] + 1 == cur)
                v.push_back(i);
        if (v.empty()) break;
        for (int u : v) {
            used[u] = true;
            --cur;
            for (int i = 1; i <= n; ++i)
                if (adj[u][i]) --d[i];
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; ++i) if (!used[i]) ans += b[i];
    cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

template <typename T>
struct modular {
    constexpr modular() : val(0){}
    constexpr modular(const modular<T>& _m) : val(_m.val) {}
    template <typename U> constexpr modular(const U& _r = U()) {
        val = -MOD <= _r && _r < MOD ? _r: _r % MOD;
        if (val < 0) { val += MOD; } }
    const T operator()() { return val; }
    template <typename U> explicit operator U() const { return static_cast<U>(val); }
    modular<T>& operator+=(const modular<T>& _m) { if ((val += _m.val) >= MOD) { val -= MOD; } return *this; }
    modular<T>& operator-=(const modular<T>& _m) { if ((val -= _m.val) < 0) { val += MOD; } return *this; }
    modular<T>& operator*=(const modular<T>& _m) { val = modular<T>(static_cast<int64_t>(val) * static_cast<int64_t>(_m.val)).val; return *this; }
    modular<T>& operator/=(const modular<T>& _m) {
        T a = _m.val, b = MOD, u = 0, v = 1;
        while (a != 0) {
            T q = b / a;
            b -= q * a; swap(a, b);
            u -= q * v; swap(u, v);
        } return *this *= u; }
    modular<T>& operator =(const modular<T>& _m) { val = _m.val; return *this; }
    template <typename U> modular<T>& operator+=(const U& _r) { return *this += modular<T>(_r); }
    template <typename U> modular<T>& operator-=(const U& _r) { return *this -= modular<T>(_r); }
    template <typename U> modular<T>& operator*=(const U& _r) { return *this *= modular<T>(_r); }
    template <typename U> modular<T>& operator/=(const U& _r) { return *this /= modular<T>(_r); }
    template <typename U> modular<T>& operator =(const U& _r) { val = modular<T>(_r).val; return *this; }
    modular<T> operator-() { return modular<T>(-val); }
    template <typename U> friend bool operator==(const modular<U>&, const modular<U>&);
    friend std::istream& operator>>(std::istream& os, modular<T>& _m) { os >> _m.val; _m *= 1; return os; }
    friend std::ostream& operator<<(std::ostream& os, const modular<T>& _m) { return os << _m.val; }
    template <typename U>
    modular<T> exp(U e) {
        modular<T> res = 1;
        modular<T> b = val;
        if (e < 0) { b = 1/b; e *= -1; }
        for (; e; e >>= 1) {
            if (e & 1) { res *= b; }
            b *= b;
        } return res; }
private:
    T val;
};
template <typename T> inline modular<T> operator+(const modular<T>& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) += _rhs; }
template <typename T, typename U> inline modular<T> operator+(const modular<T>& _lhs, const U& _rhs) { return modular<T>(_lhs) += _rhs; }
template <typename T, typename U> inline modular<T> operator+(const U& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) += _rhs; }
template <typename T> inline modular<T> operator-(const modular<T>& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) -= _rhs; }
template <typename T, typename U> inline modular<T> operator-(const modular<T>& _lhs, const U& _rhs) { return modular<T>(_lhs) -= _rhs; }
template <typename T, typename U> inline modular<T> operator-(const U& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) -= _rhs; }
template <typename T> inline modular<T> operator*(const modular<T>& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) *= _rhs; }
template <typename T, typename U> inline modular<T> operator*(const modular<T>& _lhs, const U& _rhs) { return modular<T>(_lhs) *= _rhs; }
template <typename T, typename U> inline modular<T> operator*(const U& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) *= _rhs; }
template <typename T> inline modular<T> operator/(const modular<T>& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) /= _rhs; }
template <typename T, typename U> inline modular<T> operator/(const modular<T>& _lhs, const U& _rhs) { return modular<T>(_lhs) /= _rhs; }
template <typename T, typename U> inline modular<T> operator/(const U& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) /= _rhs; }
template <typename T> inline bool operator==(const modular<T>& _lhs, const modular<T>& _rhs) { return _lhs.val == _rhs.val; }
template <typename T, typename U> inline bool operator==(const modular<T>& _lhs, const U& _rhs) { return _lhs == modular<T>(_rhs); }
template <typename T, typename U> inline bool operator==(const U& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) == _rhs; }
template <typename T> inline bool operator!=(const modular<T>& _lhs, const modular<T>& _rhs) { return !(_lhs == _rhs); }
template <typename T, typename U> inline bool operator!=(const modular<T>& _lhs, const U& _rhs) { return !(_lhs == _rhs); }
template <typename T, typename U> inline bool operator!=(const U& _lhs, const modular<T>& _rhs) { return !(_lhs == _rhs); }
typedef modular<int> mint;

const int N = 3003;
mint dp[N][N];

void solve() {
    memset(dp, 0, sizeof dp);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> w(n);
    for (auto& x: a) {
        cin >> x;
    }
    int H = 0, T = 0;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        w[i] = x;
        if (a[i]) H += x;
        else T += x;
    }
    int tot = H + T;
    dp[0][0] = 1;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j <= i; j++) {
            if (i-j <= T) {
                dp[i+1][j] += dp[i][j] * (T - (i-j)) / (tot + j - (i-j));
                dp[i+1][j+1] += dp[i][j] * (H + j) / (tot + j - (i-j));
            }
        }
    }
    mint ad = 0;
    mint mi = 0;
    for (int j = 0; j <= m; j++) {
        ad += dp[m][j] * j;
        mi += dp[m][j] * (m-j);
    }
    vector<mint> res(n);
    for (int i = 0; i < n; i++) {
        if (a[i]) {
            res[i] = w[i] + ad * w[i] / H;
        }else {
            res[i] = w[i] - mi * w[i] / T;
        }
    }
    for (auto& x: res) {
        cout << x << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define Maxn 1000
int head[Maxn+5],arrive[Maxn<<1|5],nxt[Maxn<<1|5],tot;
void add_edge(int from,int to){
	arrive[++tot]=to;
	nxt[tot]=head[from];
	head[from]=tot;
}
int n;
int sz[Maxn+5],maxn[Maxn+5];
int rt,G;
int mx(int a,int b){
	return a>b?a:b;
}
void get_root(int root,int fa){
	sz[root]=1;
	for(int i=head[root];i;i=nxt[i]){
		if(arrive[i]==fa){
			continue;
		}
		get_root(arrive[i],root);
		sz[root]+=sz[arrive[i]];
		maxn[root]=mx(maxn[root],sz[arrive[i]]);
	}
	maxn[root]=mx(maxn[root],n-sz[root]);
	if(G>maxn[root]){
		G=maxn[root];
		rt=root;
	}
}
int fa[Maxn+5];
void init_dfs(int root){
	sz[root]=1;
	for(int i=head[root];i;i=nxt[i]){
		if(arrive[i]==fa[root]){
			continue;
		}
		fa[arrive[i]]=root;
		init_dfs(arrive[i]);
		sz[root]+=sz[arrive[i]];
	}
}
vector<int> edge[Maxn+5];
bool cmp(int x,int y){
	return sz[x]>sz[y];
}
int cnt=1,t=1;
void dfs_1(int root,int w){
	printf("%d %d %d\n",fa[root],root,cnt-w);
	int now=cnt;
	cnt++;
	for(int i=0;i<(int)edge[root].size();i++){
		if(edge[root][i]==fa[root]){
			continue;
		}
		dfs_1(edge[root][i],now);
	}
}
void dfs_2(int root,int w){
	printf("%d %d %d\n",fa[root],root,cnt*t-w);
	int now=cnt*t;
	t++;
	for(int i=0;i<(int)edge[root].size();i++){
		if(edge[root][i]==fa[root]){
			continue;
		}
		dfs_2(edge[root][i],now);
	}
}
int main(){
	scanf("%d",&n);
	int u,v;
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	G=n;
	get_root(1,0);
	init_dfs(rt);
	sort(edge[rt].begin(),edge[rt].end(),cmp);
	for(int i=0;i<(int)edge[rt].size();i++){
		if(cnt*3<n){
			dfs_1(edge[rt][i],0);
		}
		else{
			dfs_2(edge[rt][i],0);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=1e5+10;
struct node{int c,id;bool operator<(const node &r)const{return c==r.c?id>r.id:c<r.c;}};
priority_queue<node>q;
ll n,m,k,c[MAXN];
ll d[MAXN],a[MAXN],k1[25],k2[25],h;
bool vis[MAXN];
queue<int>f;
int main()
{
	ios::sync_with_stdio(0);
	cin>>h>>n>>m>>k;
	for(int i=0;i<=k;++i) d[i]=1e18;
	d[1]=0;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i]>>c[i];
		if(a[i]%k==1||k==1)
			q.push((node){c[i],i});
	}
	int now=0;
	while(m--)
	{
		int op;
		ll x,y,z;
		cin>>op;
		if(op==1)
		{
			cin>>z;
			if(k==1) continue;
			k1[++now]=z/k;
			k2[now]=z%k;
			int l=0,r=0;
			for(int i=1;i<=k;++i)
				f.push(i-1);
			while(!f.empty())
			{
				x=f.front();
				f.pop();
				vis[x]=0;
				for(int i=1;i<=now;++i)
				{
					(y=x+k2[i])%=k;
					z=d[x]+k1[i]+(x+k2[i])/k;
					if(z<d[y])
					{
						d[y]=z;
						if(!vis[y])
							vis[y]=1,f.push(y);
					}
				}
			}
			while(!q.empty()) q.pop();
			for(int i=1;i<=n;++i)
				if(d[a[i]%k]<=a[i]/k&&c[i])
					q.push((node){c[i],i});
		}
		if(op==2)
		{
			cin>>x>>y;
			c[x]-=y;
			if(d[a[x]%k]<=a[x]/k||k==1)
				q.push((node){c[x],x});
		}
		if(op==3)
		{
			while(!q.empty()&&c[q.top().id]!=q.top().c) q.pop();
			if(q.empty()) cout<<"0"<<endl;
			else cout<<q.top().c<<endl,c[q.top().id]=0,q.pop();
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define NAME "data"
using namespace std;
typedef long long LL;
typedef double DB;
typedef pair <LL, LL> pLL;
const int NMAX = 3e5+7;
const LL MOD = 998244353;

int n;
vector <int> a[NMAX];
LL f[3][NMAX];

LL rv(LL a, LL b = MOD) {
    LL xa, xb, xr, r;
    xa = 1; xb = 0;
    while(b != 0) {
        LL q = a / b;
        r = a - b*q;
        xr = xa - xb*q;
        a = b; xa = xb;
        b = r; xb = xr;
    }
    return (xa+MOD)%MOD;
}

void dp(int u, int p) {
    for(auto v : a[u])
        if(v != p) dp(v, u);

    f[0][u] = 1;
    for(auto v : a[u])
    if(v != p) f[0][u] = f[0][u] * ((f[0][v]+f[1][v])%MOD) % MOD;

    LL tmp = 1;
    for(auto v : a[u])
    if(v != p)
        tmp = tmp * (f[0][v]+f[1][v]*2%MOD) % MOD;
    for(auto v : a[u])
    if(v != p)
        f[1][u] = (f[1][u] + tmp * rv(f[0][v]+2*f[1][v]%MOD) % MOD * ((f[0][v]+f[2][v])%MOD) % MOD) % MOD;

    LL tmp1 = 1;
    LL tmp2 = 1;
    for(auto v : a[u])
    if(v != p) {
        tmp1 = tmp1 * ((f[1][v]*2%MOD+f[0][v])%MOD) % MOD;
        tmp2 = tmp2 *((f[1][v]+f[0][v])%MOD) % MOD;
    }
    f[2][u] = (tmp1 - tmp2 + MOD*MOD) % MOD;

    //cerr << u << " : " << f[0][u] << ' ' << f[1][u] << ' ' << f[2][u] << '\n';
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(NAME".inp", "r", stdin);
    //freopen(NAME".out", "w", stdout);
    cin >> n;
    for(int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    dp(1, 1);
    cout << (f[1][1] + f[0][1])%MOD;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=510,mod=1e9+7;
int n,m,a[N],b[N],c[N],z[N],A[N],B[N];
ll K;

void inc(int &x,int y){ x=x+y>=mod ? x+y-mod : x+y;}
void dec(int &x,int y){ x=x-y<0 ? x-y+mod : x-y;}

void mult(int u[],int v[]){
	memset(z,0,sizeof(z));
	rep(i,0,249) rep(j,0,249) z[i+j]=(z[i+j]+1LL*u[i]*v[j])%mod;
	for(int i=498; i>=250; i--)
		rep(j,1,m) inc(z[i-b[j]],z[i]);
	rep(i,0,249) u[i]=z[i];
}

void ksm(int c[],ll n){
	memset(A,0,sizeof(A));
	A[0]=1;
	while(n){
		if(n&1) mult(A,c);
		n>>=1,mult(c,c);
	}
}

int main(){
	cin>>n>>m>>K;
	rep(i,1,n) scanf("%d",&a[i]);
	rep(i,1,m) scanf("%d",&b[i]);
	rep(i,1,n){
		memset(c,0,sizeof(c));
		c[1]=1; ksm(c,a[i]);
		rep(j,0,249) inc(B[j],A[j]);
	}
	ksm(B,K);
	rep(i,0,249) B[i]=A[i];
	for(int i=249; i>0; i--) rep(j,1,m) if(i>=b[j]) inc(B[i-b[j]],B[i]);
	cout<<B[0]<<endl;
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
ll mod = 1000000009;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
    ll res = 1;
    while (n) {
        if (n & 1)res = res * x % m;
        x = x * x % m; n >>= 1;
    }
    return res;
}
struct modint {
    ll n;
    modint() :n(0) { ; }
    modint(ll m) :n(m) {
        if (n >= mod)n %= mod;
        else if (n < 0)n = (n % mod + mod) % mod;
    }
    operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
    if (n == 0)return modint(1);
    modint res = (a * a) ^ (n / 2);
    if (n % 2)res = res * a;
    return res;
}

ll inv(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
    fact[0] = modint(1);
    for (int i = 0; i < max_n - 1; i++) {
        fact[i + 1] = fact[i] * modint(i + 1);
    }
    factinv[max_n - 1] = modint(1) / fact[max_n - 1];
    for (int i = max_n - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * modint(i + 1);
    }
}
modint comb(int a, int b) {
    if (a < 0 || b < 0 || a < b)return 0;
    return fact[a] * factinv[b] * factinv[a - b];
}

using mP = pair<modint, modint>;
mP mul(mP a, mP b) {
    return { a.first * b.first,a.second * b.first + a.first * b.second };
}
mP plu(mP a, mP b) {
    return { a.first + b.first,a.second + b.second };
}

mP dp[501];
bool used[501];
void init() {
    init_f();
    dp[0] = { 1,0 };
    dp[1] = { 2,0 };
    for (int n = 2; n <= 500; n++) {
        rep(j, n) {
            modint cnt = n + 1; modint sum = 0;
            rep(k, n)sum += abs(j - k);
            mP cl = dp[j];
            mP cr = dp[n - 1 - j];
            mP x = mul(cl, cr);
            x.first *= comb(n - 1, j);
            x.second *= comb(n - 1, j);
            x = mul(x, { cnt,sum });
            dp[n] = plu(dp[n], x);
        }
    }
}

mP dp2[502][501];
void solve() {
    int n, m; cin >> n >> m >> mod;
    init();
    dp2[0][0] = { 1,0 };
    rep(i, n) {
        rep(k, i + 1) {
            for (int j = i; j < n; j++) {
                int ni = j + 2; ni = min(ni, n);
                int nk = k + j - i + 1;
                if (nk <= m) {
                    mP x = mul(dp2[i][k], dp[j - i + 1]);
                    x.first *= comb(nk, k);
                    x.second *= comb(nk, k);
                    dp2[ni][nk] = plu(dp2[ni][nk], x);
                }
            }
            dp2[i + 1][k] = plu(dp2[i + 1][k], dp2[i][k]);
        }
    }
    modint ans = dp2[n][m].second;
    cout << ans << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(15);
     //init_f();
     //init();
     //expr();
     //int t; cin >> t; rep(i, t)
    solve();
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << x << endl

using namespace std;
const int MAX_N = 33;

const long long MOD = 1000000007;
long long dp[MAX_N][2][2][2];
long long numb[MAX_N][2][2][2];
int query;
int X1, Y1, X2, Y2, k;

vector <int> change(int r) {
	vector <int> res;
	for (int i = 0; i < 31; i++) {
		if ((long long) r & (1LL << (long long) i)) {
			res.push_back(1);
		}
		else {
			res.push_back(0);
		}
	}

	return res;
}

long long calc(int x, int y) {
	if (x == 0 || y == 0) {
		return 0;
	}

	memset(dp, 0LL, sizeof(dp));
	memset(numb, 0LL, sizeof(numb));
	vector <int> X, Y, K;
	X = change(x - 1);
	Y = change(y - 1);
	K = change(k - 1);
  long long res = 0LL;

  numb[31][1][1][1] = 1;

	for (int i = 31; i >= 1; i--) {
		//cout << i << endl;
		for (int flagX = 0; flagX <= 1; flagX++) {
			for (int flagY = 0; flagY <= 1; flagY++) {
				for (int flagK = 0; flagK <= 1; flagK++) {
					//cout << dp[i][flagX][flagY][flagK] << endl;
					if (numb[i][flagX][flagY][flagK] == 0) {
						continue;
					}

					//cout << i << ' ' << flagX << ' ' << flagY << ' ' << flagK << ' ' << numb[i][flagX][flagY][flagK] << ' ' << dp[i][flagX][flagY][flagK] << endl;
					for (int b1 = 0; b1 <= 1; b1++) {
						for (int b2 = 0; b2 <= 1; b2++) {
							if ((flagX == 1 && b1 > X[i - 1]) || (flagY == 1 && b2 > Y[i - 1]) || (flagK == 1 && ((b1 ^ b2) > K[i - 1]))) {
								continue;
							}

              int nflagX = (flagX == 1 && b1 == X[i - 1]);
              int nflagY = (flagY == 1 && b2 == Y[i - 1]);
              int nflagK = (flagK == 1 && ((b1 ^ b2) == K[i - 1]));
              (numb[i - 1][nflagX][nflagY][nflagK] += numb[i][flagX][flagY][flagK]) %= MOD;
              (dp[i - 1][nflagX][nflagY][nflagK] += ((dp[i][flagX][flagY][flagK] * 2LL) % MOD + numb[i][flagX][flagY][flagK] * (b1 ^ b2)) % MOD) %= MOD;
						}
					}
				}
			}
		}
	}

	for (int flagX = 0; flagX <= 1; flagX++) {
		for (int flagY = 0; flagY <= 1; flagY++) {
			for (int flagK = 0; flagK <= 1; flagK++) {
				(res += dp[0][flagX][flagY][flagK]) %= MOD;
				(res += numb[0][flagX][flagY][flagK]) %= MOD;
			}
		}
	}

	//cout << res << endl;

	return res;
}

int main () {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d", &query);
	while (query--) {
		scanf("%d %d %d %d %d", &X1, &Y1, &X2, &Y2, &k);
		long long res = calc(X2, Y2);
		res -= calc(X1 - 1, Y2);
		res -= calc(X2, Y1 - 1);
		(res += 3LL * MOD) %= MOD;
		(res += calc(X1 - 1, Y1 - 1)) %= MOD;
		printf("%I64d\n", res);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>

#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define sz(v) int(v.size())

using namespace std;

int gdt(int,int);

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

int t2(int b, int d) {
    int r = 0;
    while (gcd(b,d) != 1) r++, d /= gcd(b,d);
    return d == 1 ? r : 0;
}

bool t6(int b, int d) {
    int D = d;

    int c = 2;
    while (d > 1) {
        int r = 1;
        while (d % c == 0) {
            d /= c;
            r *= c;
        }
        if (r == D) return false;
        if (gdt(b,r) == 7) return false;
        c++;
    }
    return true;
}

int gdt(int b, int d) {
    if (t2(b,d)) return 2;
    else if (b % d == 1) return 3;
    else if (b % d == d-1) return 11;
    else if (t6(b,d)) return 6;
    else return 7;
}

int main() {
    int b, d;
    scanf("%d %d", &b, &d);
    int T = gdt(b,d);
    printf("%d-type\n", gdt(b,d));
    if (T == 2) printf("%d\n", t2(b,d));
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

vector <int> ms = {(int) (1e9 + 7), (int) (1e9 + 9), (int) (998244353)};
vector <int> bs;

struct hash_str {
  vector <int> h[3], p[3];
  hash_str(vector <pair <int, int> > e) {
    if (!e.empty()) {
      for (int i = 0; i < 3; i++) {
        h[i].resize(e.size());
        p[i].resize(e.size());
        h[i][0] = e[0].second + 1;
        p[i][0] = 1;
        for (int j = 1; j < (int) e.size(); j++) {
          h[i][j] = (h[i][j - 1] * (ll) bs[i] + e[j].second + 1) % ms[i];
          p[i][j] = (p[i][j - 1] * (ll) bs[i]) % ms[i];
        }
      }
    }
  }
  string get(int l, int r) {
    string s = "";
    for (int i = 0; i < 3; i++) {
      int hsh = 0;
      if (!l) {
        hsh = h[i][r];
      } else {
        hsh = h[i][r] - (h[i][l - 1] * (ll) p[i][r - l + 1]) %  ms[i];
        if (hsh < 0) hsh += ms[i];
      }
      s += to_string(hsh);
    }
    return s;
  }
};

int main() {
#ifdef iq
	freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  mt19937 rnd(time(0));
  string s = "asdasdasdfafdsfahfdashfdashfdashdahfkljdhsfkljdhasfhdsshfjdashfhyruyqrweyruoqewyryqew";
  for (int i = 0; i < (int) s.size(); i++) rnd();
  for (int i = 0; i < 3; i++) {
    if (i == 0) {
      string s = "asdasdasfdasfdasfhdasjhfvhfhfdlashfdashvkljdashfdashfjdhaskljfhfhhfshfkljashfkljdashhfdaslfhdasyhfryupwyerupqhqwurqewyewpuirhfasjfkldhsfkljdhsjflashduyfuqew  ory        \n        21321321  ";
      int x = rnd() % 256;
      for (auto c : s) {
        x += c;
      }
      x %= 256;
      bs.push_back(x + 200);
    } else {
      bs.push_back((bs.back() * 12345 + rnd() % 23) % 256 + 200);
    }
  }//yes I forgot how to write a good random
  int n;
  cin >> n;
  string t;
  cin >> t;
  vector <pair <int, int> > a, b;
  int chet = 0;
  vector <int> p(n);
  for (int i = 0; i < (int) t.size(); i++) {
    if (t[i] == '1') chet ^= 1;
    p[i] = chet;
    if (t[i] == '0') {
      a.push_back({i, chet});
      b.push_back({i, chet ^ 1});
    }
  }
  hash_str x(a);
  hash_str y(b);
  int q;
  cin >> q;
  auto f_a = [&] (int l, int r) {
    return x.get(l, r);
  };
  auto f_b = [&] (int l, int r) {
    return y.get(l, r);
  };
  auto get = [&] (int l, int r, int chet) {
    int x = -1, y = -1;
    {
      int vl = -1, vr = (int) a.size();
      while (vl < vr - 1) {
        int vm = (vl + vr) / 2;
        if (a[vm].first < l) {
          vl = vm;
        } else {
          vr = vm;
        }
      }
      x = vl + 1;
    }
    {
      int vl = -1, vr = (int) a.size();
      while (vl < vr - 1) {
        int vm = (vl + vr) / 2;
        if (a[vm].first <= r) {
          vl = vm;
        } else {
          vr = vm;
        }
      }
      y = vl;
    }
    if (x > y) {
      string s = "";
      return make_pair(0, s);
    } else {
      if (!chet)
        return make_pair(y - x + 1, f_a(x, y));
      else
        return make_pair(y - x + 1, f_b(x, y));
    }
  };
  auto f = [&] (int l, int r) {
    if (l && p[l - 1]) return get(l, r, 1);
    else return get(l, r, 0);
  };
  while (q--) {
    int l1, l2, len;
    cin >> l1 >> l2 >> len;
    l1--, l2--;
    if (f(l1, l1 + len - 1) != f(l2, l2 + len - 1)) {
      cout << "No\n";
    } else {
      cout << "Yes\n";
    }
  }
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

vector <long long> happy;

void rec (int md, int d = 0, long long x = 0)
{
    if (d == md)
    {
        happy.push_back(x);
        return;
    }
    for (int i = 0; i < 2; i++)
    {
        x *= 10;
        if (i)
            x += 7;
        else
            x += 4;
        rec(md, d + 1, x);
        x /= 10;
    }
    return;
}

long long pl, pr, vl, vr, k;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long res = 0;
    happy.push_back(0);
    for (long long i = 1; i < 11; i++)
        rec(i);
    cin >> pl >> pr >> vl >> vr >> k;
    for (int i = 1; i < happy.size() - k; i++)
    {
        long long a = (min(pr, happy[i]) - max(happy[i - 1] + 1, pl) + 1);
        long long b = (min(vr, happy[i + k] - 1) - max(happy[i + k - 1], vl) + 1);
        long long c = (min(vr, happy[i]) - max(happy[i - 1] + 1, vl) + 1);
        long long d = (min(pr, happy[i + k] - 1) - max(happy[i + k - 1], pl) + 1);
        if (a > 0 && b > 0)
            res += a * b;
        if (c > 0 && d > 0)
            res += c * d;
        if (k == 1 && pl <= happy[i] && happy[i] <= pr && vl <= happy[i] && happy[i] <= vr)
            res--;
    }
    printf("%.12lf", (double)res / (double)((pr - pl + 1) * (vr - vl + 1)));
    return 0;
}


//CLOCKS_PER_SEC
using namespace std;
#include<bits/stdc++.h>
#define sqr(x) (x)*(x)
//#define sort stable_sort
#define ll long long
#define mk make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mk(mk(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#define all(x) (x).begin(),(x).end()
#define titose CLOCKS_PER_SEC
#define fpi(x) freopen(x,"r",stdin);
#define fpo(x) freopen(x,"w",stdout);
#define fprio fpi("in.txt");fpo("out.txt");
#define fast ios_base::sync_with_stdio(false);
inline void read(int &x){int v=0,f=1;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void read(ll &x){ll v=0ll,f=1ll;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void readc(char &x){char c;while (((c=getchar())==' ')||c=='\n');x=c;}
inline void writes(string s){puts(s.c_str());}
inline void writeln(){writes("");}
inline void writei(int x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
inline void writell(ll x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
#define sl set<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define msi map<string,int>
#define msl map<string,ll>
#define piii pair<int,pii >
#define piipi pair<pii,int>
#define plll pair<ll,pll >
#define pllpl pair<pll,ll>
#define pqi priority_queue<int>
#define pql priority_queue<ll>
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define forup(i,a,b) for ((i)=(a);(i)<=(b);(i)++)
#define fordo(i,a,b) for ((i)=(a);(i)>=(b);(i)--)
#define rep(i,x) forup ((i),1,(x))
#define repd(i,x) fordo ((i),(x),1)
#define itr iterator
#define fe(itcalc,c) for(__typeof((c).begin()) itcalc=(c).begin();itcalc!=(c).end();itcalc++)
#define NO {cout<<"NO";return 0;}
#define YES {cout<<"YES";return 0;}
#define y0 y000000000000000000000000000
#define y1 y111111111111111111111111111
#define j0 j000000000000000000000000000
#define j1 j111111111111111111111111111
#define cl0(a) memset((a),(0),(sizeof((a))))
#define clz(a) memset((a),(0x16),(sizeof((a))))
#define clf(a) memset((a),(-(0x16)),(sizeof((a))))
#define inf 0x3bbbbbbb
#define lnf 0x1bbbbbbbbbbbbbbbll
#define sqrt divi
#define p2(i) (1ll<<(i))
#define readi read
#define readll read
/*************************************************/
int mod=998244353;
void add(int &x,int y)
{
	x+=y;
	if(x>=mod) x-=mod;
}
int n,m,i,j,msk,cpx,cnx,cpy,cny,bx,by,dp[31][21][21][21][21][2][2],x[15],y[15],px[1<<5],py[1<<5],nx[1<<5],ny[1<<5];
int main()
{
	read(n);read(m);
	rep(i,n){
		read(x[i]);
		read(y[i]);
	}
	forup(i,0,(1<<n)-1){
		rep(j,n){
			if((i>>(j-1))&1){
				(x[j]>0?px[i]:nx[i])+=abs(x[j]);
				(y[j]>0?py[i]:ny[i])+=abs(y[j]);
			}
		}
	}
	dp[0][0][0][0][0][0][0]=1;
	forup(i,0,29){
		forup(cpx,0,19)forup(cnx,0,19)forup(cpy,0,19)forup(cny,0,19){
			forup(bx,0,1)forup(by,0,1)if(dp[i][cpx][cnx][cpy][cny][bx][by]){
				forup(msk,0,(1<<n)-1){
					int npx=cpx+px[msk];
					int npy=cpy+py[msk];
					int nnx=cnx+nx[msk];
					int nny=cny+ny[msk];
					if((npx&1)!=(nnx&1)) continue;
					if((npy&1)!=(nny&1)) continue;
					int cx=(npx&1),cy=(npy&1);
					int mx=((m>>i)&1),my=mx;
					add(dp[i+1][npx>>1][nnx>>1][npy>>1][nny>>1][(cx==mx)?bx:(cx>mx)][(cy==my)?by:(cy>my)],dp[i][cpx][cnx][cpy][cny][bx][by]);
				}
			}
		}
	}
	cout<<(dp[30][0][0][0][0][0][0]+mod-1)%mod;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 2005
struct node{
	double x,y;
	int pos;
	bool flag;
}p[N];
int read(){
	char ch=getchar();
	while(ch!='L'&&ch!='R')ch=getchar();
	return ch=='L';
}
double cross(double x1,double y1,double x2,double y2){
	return (x1*y2-x2*y1);
}
double compare(node a,node b,node c){
	return cross((b.x-a.x),(b.y-a.y),(c.x-a.x),(c.y-a.y));
}
bool cmp(node a,node b){
	if(a.y!=b.y)return a.y<b.y;
	return a.x<b.x;
}
int n,a[N],ans[N];
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lf%lf",&p[i].x,&p[i].y);
		p[i].pos=i,p[i].flag=1;
	}
	for(int i=1;i<=n-2;i++)
		a[i]=read();
	sort(p+1,p+n+1,cmp);
	ans[1]=p[1].pos,p[1].flag=0;
	int t=1,la=1;
	for(int i=1;i<=n-2;i++){
		if(a[i])for(int j=1;j<=n;j++){
			if(!p[j].flag)continue;
			if(!p[t].flag||compare(p[la],p[j],p[t])>0)t=j;
		}
		else for(int j=1;j<=n;j++){
			if(!p[j].flag)continue;
			if(!p[t].flag||compare(p[la],p[j],p[t])<0)t=j;
		}
		ans[i+1]=p[t].pos,p[t].flag=0,la=t;
	}
	for(int i=1;i<=n;i++)
		if(p[i].flag){
			ans[n]=p[i].pos;
			break;
		}
	for(int i=1;i<=n;i++)
		printf("%lld ",ans[i]);
	return 0;
}


#include <string.h>
#include <sstream>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <set>

#include <map>
#include <vector>
#include <string>
#include <stdlib.h>

#define ll long long
#define clr(x) memset(x,0,sizeof(x))
#define _clr(x) memset(x,-1,sizeof(x))
#define fr(i,a,b) for(int i = a; i < b; ++i)
#define frr(i,a,b) for(int i = a; i > b; --i)
#define pb push_back
#define sf scanf

#define pf printf
#define mp make_pair

using namespace std;
const ll mod = 1000000007;
const int MAXN = 10000005;
const double eps = 1e-6;
int n,m,z;
ll a[1000000];
int cmd[500010], v[500010],l[500010],r[500010],t[500010], s[1000010],val[1000010];

map<int,int> time_idx, pre_time,ft;
int idx;

void add_t(int t) {
	if(time_idx.find(t)==time_idx.end()) {
		pre_time[idx]=t;
		time_idx[t]=idx++;
	}
}

void push_down(int node) {
}

struct Info{

	ll s0;
	ll st;
	ll min_v;
	ll sp;
	ll start_time;
	ll end_time;
	int flag;
	Info(){flag = 0;}

}info[1000010];

Info merge(const Info &lt, const Info &rt) {
	//printf("lt flag %d rt flag %d\n",lt.flag, rt.flag);
	Info cur;
	if(lt.flag&&rt.flag) {
		int ed = lt.end_time;
		int sd = rt.start_time;
		ll ssp = lt.st + (sd-ed)*lt.sp;
		//printf("ssp = %lld ed = %d sd  = %d st = %lld sp = %lld\n",ssp,ed,sd, lt.st,lt.sp);
		cur.s0 = lt.s0;
		cur.st = ssp+rt.st;
		cur.min_v = min(lt.min_v,min(ssp,rt.min_v+ssp));
		cur.sp = rt.sp;
		cur.start_time = lt.start_time;
		cur.end_time = rt.end_time;
		cur.flag = 1;
	}
	else if(lt.flag) {
		cur = lt;
	}
	else if(rt.flag) {
		cur = rt;
	}
	return cur;
}

void push_up(int node, int l, int r) {
	Info lt = info[node<<1], rt = info[node<<1|1];
	info[node]=merge(lt,rt);
}

void add(int node, int l, int r, int t_idx, int v, int flag) {
	//printf("l = %d r = %d idx = %d v = %d\n",l,r,t_idx,v);
	if(l==r&&l==t_idx) {
		val[r] = v;
		info[node].s0 = 0;
		info[node].st = 0;
		info[node].min_v = 0;
		info[node].sp=v;
		info[node].start_time=pre_time[l];
		info[node].end_time=pre_time[r];

		if(flag>0) {
			info[node].flag=1;
		}
		else {
			info[node].flag=0;
		}
		//printf("node = %d v = %d flag = %d\n",node,v, flag);
		return;
	}

	int mid = (l+r)>>1;
	if(mid>=t_idx) {
		add(node<<1,l,mid,t_idx,v,flag);
	}
	else {
		add(node<<1|1,mid+1,r,t_idx,v,flag);
	}
	push_up(node,l,r);
	Info cur = info[node];
	//printf("l = %d r = %d s0 = %lld st = %lld start = %lld end = %lld min = %lld flag %d\n",l,r,cur.s0,cur.st,cur.start_time,cur.end_time,cur.min_v, cur.flag);
}

Info query(int node, int l, int r, int ql, int qr) {
	//printf("query l = %d r = %d ql = %d qr = %d\n",l,r, ql, qr);
	if(ql<=l&&qr>=r) {
		return info[node];
	}
	if(ql>r||qr<l) {
		return Info();
	}

	int mid = (l+r)>>1;
	if(qr<=mid) {
		return query(node<<1,l,mid,ql,qr);
	}
	else if(ql>mid) {
		return query(node<<1|1,mid+1,r,ql,qr);
	}

	Info sum1 = query(node<<1,l,mid,ql,qr);
	Info sum2 = query(node<<1|1,mid+1,r,ql,qr);
	return merge(sum1,sum2);
}

double cal(double start,double end, int v) {

	auto it1 = ft.lower_bound(start);
	auto it2 = ft.upper_bound(end);
	if(it2!=ft.begin()) {
		it2--;
		if(it1->second > it2->second) return 0;
		//printf("cal start = %lf end = %lf v= %d\n",start,end,v);
		Info sum;
		if(it1->second!=it2->second) {
			sum = query(1,0,idx-1,it1->second,it2->second);
			//printf("sum %lld\n",sum.sp);
		}
		else {
			sum.st = 0;
			sum.sp = val[it2->second];
			sum.end_time = it2->first;
			sum.start_time = it2->first;
			sum.min_v = 0;
		}
		double left_t = end-sum.end_time;
		double res = sum.st+sum.sp*left_t;
		//printf("st = %lld sp = %lld res = %.10lf\n",sum.st,sum.sp,res);
		double min_v = min((double)sum.min_v, res);
		//printf("total sum = %lf left = %lf min = %lf last = %lld end = %lf last end = %lld\n",res, left_t, min_v,sum.sp, end, sum.end_time);
		return min_v;
	}
	else {
		return 0;
	}
}

void query(int start,int end, int v) {
	if(v==0) {
		printf("%d\n",start);
		return;
	}
	auto it1 = ft.lower_bound(start);
	auto it2 = ft.lower_bound(end);
	if(it1 == it2) {
		printf("-1\n");
		return;
		if(it1==ft.begin()) {
			printf("-1\n");
			return;
		}
		else {
			it1--;
			ll s = val[it1->second];
			ll sum = s*(end-start);
			double x = (double)v/s;
			if(start+x>end+eps) {
				printf("-1\n");
			}
			else {
				printf("%.6lf\n",start+x);
			}
			return;
		}
	}

	//printf("query start = %d end = %d v = %d\n",start,end,v);
	double l = start, r = end+eps;
	for(int i = 0; i < 48&&fabs(l-r)>eps; ++i) {
		double mid =(l+r)/2.0;
		double sum = cal(start,mid,v);
		if(sum+v>eps){
			l = mid;
		}
		else {
			r = mid;
		}
	}
	//printf("l = %lf r = %lf\n",l,r);
	double t = cal(start,r,v);
	//printf("l = %lf r = %lf sum = %.10lf, %d\n",l,r,t, (t+v)>eps);
	t+=v;
	//printf("l = %lf t = %.10lf check %d\n",r,t, (t-eps)>=0);
	if(t>eps) printf("-1\n");
	else printf("%.6lf\n",r);
}

void sol(){
	fr(i,0,n) {
		//printf("i = %d\n",i);
		if(cmd[i]==1) {
			add(1,0,idx-1,time_idx[t[i]],s[i],1);
			ft[t[i]]=time_idx[t[i]];
		}
		else if(cmd[i]==2) {
			add(1,0,idx-1,time_idx[t[i]],0,0);
			ft.erase(ft.find(t[i]));
		}
		else {
			query(l[i],r[i],v[i]);
		}
	}
}

int main(){

	idx = 0;
	sf("%d",&n);
	vector<int> xxx;
	fr(i,0,n) {
		sf("%d",&cmd[i]);
		if(cmd[i]==1) {
			sf("%d%d",&t[i],&s[i]);
			xxx.pb(t[i]);
		}
		else if(cmd[i]==2) {
			sf("%d",&t[i]);
		}
		else if(cmd[i]==3) {
			sf("%d%d%d",&l[i],&r[i],&v[i]);
		}
	}
	sort(xxx.begin(), xxx.end());
	int pos = unique(xxx.begin(), xxx.end())-xxx.begin();
	for(int i = 0; i < pos; ++i) {
		add_t(xxx[i]);
	}
	sol();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 66

int r, c, n, i;
char s[maxN];
ll comb[maxN][maxN];

int cnt_a[maxN], cnt_b[maxN];
vector<ll> partial[maxN], partial_zero[maxN];

void compute_comb() {
    int i, j;

    for (i = 0; i <= n; i++) {
        comb[i][0] = 1;
        for (j = 1; j <= i; j++)
            comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
    }
}

ll get_difs(int conf, int a_bef, int b_bef) {
    int i;
    ll ans = 0;
    ll aux1, aux2;

    for (i = 0; i < c + 1; i++) {
        if (conf & (1 << i)) {
            //! here comes a B
            b_bef++;

            aux1 = comb[b_bef - 1][r - 1];
            aux2 = comb[n - b_bef][r] - comb[a_bef][r];

            ans -= aux1 * aux2;
        } else {
            //! here comes an A
            a_bef++;

            aux1 = comb[a_bef - 1][r - 1];
            aux2 = comb[n - a_bef][r] - comb[b_bef][r];

            ans += aux1 * aux2;
        }
    }

    return ans;
}

bool check(int conf) {
    int i;

    for (i = 0; i < c + 1; i++) {
        if (s[2 * r + c + i] == 'A' && ( (conf >> i) & 1 ) == 1) return false;
        if (s[2 * r + c + i] == 'B' && ( (conf >> i) & 1 ) == 0) return false;
    }

    return true;
}

void compute_second_part() {
    int i, conf;
    int limit = 1 << (c + 1);
    int a_here, b_here;

    for (conf = 0; conf < limit; conf++) {
        b_here = __builtin_popcount(conf);
        a_here = c + 1 - b_here;

        if (check(conf))
            partial[a_here].pb(get_difs(conf, r + c - a_here, r + c - b_here));
        else
            partial_zero[a_here].pb(get_difs(conf, r + c - a_here, r + c - b_here));
    }

    for (i = 0; i <= c + 1; i++) {
        sort(partial[i].begin(), partial[i].end());
        sort(partial_zero[i].begin(), partial_zero[i].end());
    }
}

ll get_coef(int conf) {
    int i, j;

    for (i = 0; i < c + 1; i++)
        if ( ((conf >> i) & 1) != (conf & 1) )
            break;

    for (j = i; j < c + 1; j++) {
        if (s[2 * r - 1 + j] == 'A' && (( (conf >> j) & 1 ) == 1)) return 0;
        if (s[2 * r - 1 + j] == 'B' && (( (conf >> j) & 1 ) == 0)) return 0;
    }

    int set_a = r - 1 + ( (conf & 1) == 0 ? i : 0 );
    int set_b = r - 1 + ( (conf & 1) == 1 ? i : 0 );

    if (set_a < cnt_a[2 * r - 2 + i]) return 0;
    if (set_b < cnt_b[2 * r - 2 + i]) return 0;
    return comb[set_a + set_b - cnt_a[2 * r - 2 + i] - cnt_b[2 * r - 2 + i]][set_a - cnt_a[2 * r - 2 + i]];
}

void upd(pair<ll, ll>& ans, pair<ll, ll> act) {
    if (act.first < 0) act.first = -act.first;

    if (ans.first < act.first) return;
    if (ans.first > act.first) {
        ans = act;
        return;
    }

    ans.second += act.second;
}

ll how_many(vector<ll>& data, ll val) {
    auto it1 = lower_bound(data.begin(), data.end(), val);
    auto it2 = upper_bound(data.begin(), data.end(), val);
    return it2 - it1;
}

ll compute_first_part() {
    int i, conf;
    int limit = 1 << (c + 1);
    int a_here, b_here;
    ll act, coef, coef2;
    pair<ll, ll> ans = mp(1LL << 60, 0);

    for (conf = 0; conf < limit; conf++) {
        b_here = __builtin_popcount(conf);
        a_here = c + 1 - b_here;
        act = get_difs(conf, r - 1, r - 1);

        //! coef may be != 0
        coef = get_coef(conf);
        auto it = lower_bound(partial[c + 1 - a_here].begin(),
                              partial[c + 1 - a_here].end(),
                              -act);

        if (it != partial[c + 1 - a_here].end()) {
            if (ans.first >= abs(*it + act)) {
                coef2 = how_many(partial[c + 1 - a_here], *it);
                upd(ans, mp(*it + act, coef * coef2));
            }
        }

        if (it != partial[c + 1 - a_here].begin()) {
            it--;
            if (ans.first >= abs(*it + act)) {
                coef2 = how_many(partial[c + 1 - a_here], *it);
                upd(ans, mp(*it + act, coef * coef2));
            }
        }

        //! coef is clearly 0
        coef = 0;
        it = lower_bound(partial_zero[c + 1 - a_here].begin(),
                         partial_zero[c + 1 - a_here].end(),
                         -act);

        if (it != partial_zero[c + 1 - a_here].end()) {
            coef2 = how_many(partial[c + 1 - a_here], *it);
            if (ans.first >= abs(*it + act)) {
                coef2 = how_many(partial[c + 1 - a_here], *it);
                upd(ans, mp(*it + act, coef * coef2));
            }
        }

        if (it != partial_zero[c + 1 - a_here].begin()) {
            it--;
            if (ans.first >= abs(*it + act)) {
                coef2 = how_many(partial[c + 1 - a_here], *it);
                upd(ans, mp(*it + act, coef * coef2));
            }
        }
    }

    return ans.second;
}

int main()
{
    //freopen("test.in","r",stdin);

    scanf("%d%d\n%s", &r, &c, s + 1);
    n = 2 * (r + c);

    compute_comb();

    for (i = 1; i <= n; i++) {
        cnt_a[i] = cnt_a[i - 1] + (s[i] == 'A' ? 1 : 0);
        cnt_b[i] = cnt_b[i - 1] + (s[i] == 'B' ? 1 : 0);
    }

    compute_second_part();
    ll sol = compute_first_part();

    printf("%lld", sol);

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

vector<int> v1, v2, ps1, ps2; string s1, s2, aux1, aux2;
vector<pair<int, int>> ans, aux;

void addLast(string &str, vector<int> &pos) {
    for (int i = 0, j = 0; i < str.length(); i = j) {
        while (j < str.length() and str[j] == str[i]) {
            ++j; }
        pos.push_back(j - 1); } }

inline int siz(vector<int> &pos, int p) {
    if (p < 0 or !pos.size()) {
        return 0; }
    if (p >= pos.size()) {
        return pos.back() + 1; }
    return pos[p] + 1; }

void solve(string &str1, string &str2, vector<pair<int, int>> &ans) {
    ps1.clear(); ps2.clear(); addLast(str1, ps1); addLast(str2, ps2);
    int c1 = (int) max(ps1.size() - (ps1.size() and str1.back() == 'a'),
                       ps2.size() - (ps2.size() and str2.back() == 'b')),
        c2 = (int) max(ps1.size() - (ps1.size() and str1.back() == 'b'),
                       ps2.size() - (ps2.size() and str2.back() == 'a'));
    if (c1 <= c2) { // move 'a' to string 1, 'b' to string 2
        int p1 = (int) ps1.size() - 1, p2 = (int) ps2.size() - 1;
        if (ps1.size() and str1.back() == 'a') { --p1; }
        if (ps2.size() and str2.back() == 'b') { --p2; }
        for (bool ok = false; p1 >= 0 or p2 >= 0; --p1, --p2, ok ^= true) {
            ans.push_back(!ok ? make_pair(siz(ps1, p1), siz(ps2, p2)) :
                                make_pair(siz(ps2, p2), siz(ps1, p1))); } }
    else {
        int p1 = (int) ps1.size() - 1, p2 = (int) ps2.size() - 1;
        if (ps1.size() and str1.back() == 'b') { --p1; }
        if (ps2.size() and str2.back() == 'a') { --p2; }
        for (bool ok = false; p1 >= 0 or p2 >= 0; --p1, --p2, ok ^= true) {
            ans.push_back(!ok ? make_pair(siz(ps1, p1), siz(ps2, p2)) :
                                make_pair(siz(ps2, p2), siz(ps1, p1))); } } }

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> s1 >> s2; bool ok = false;
    addLast(s1, v1); addLast(s2, v2);
    if (v1.size() > v2.size()) {
        swap(v1, v2); swap(s1, s2); ok = true; }
    solve(s1, s2, ans);
    for (int i = -1; i <= min(3, (int) v1.size()); ++i) {
        int x = (int) max(-1, (int)((v2.size() - v1.size()) / 2 - 3)),
            y = (int) min(v2.size(), (v2.size() - v1.size()) / 2 + 3);
        for (int j = x; j <= y; ++j) {
            int p1 = siz(v1, i), p2 = siz(v2, j);
            aux2 = s1.substr(0, p1) + s2.substr(p2);
            aux1 = s2.substr(0, p2) + s1.substr(p1);
           // cerr << aux1 << " " << aux2 << "\n";
            aux.clear(); aux.push_back(make_pair(p1, p2));
            solve(aux1, aux2, aux);
            if (aux.size() < ans.size()) {
                ans = aux; } } }
    cout << ans.size() << "\n";
    if (ok) {
        for (pair<int, int> &p : ans) {
            swap(p.first, p.second); } }
    for (pair<int, int> p : ans) {
        cout << p.first << " " << p.second << "\n"; }
    return 0; }


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;

char A[maxn],B[maxn];
int f[30];
int to[30];
int dp[1 << 20],vis[1 << 20];
int n;

int ufind(int x){
    return x == f[x] ? x : f[x] = ufind(f[x]);
}

int main(){
    int T; scanf("%d",&T);
    while(T-- ){
        scanf("%d",&n);
        scanf("%s%s",A + 1,B + 1);
        memset(to,0,sizeof(to));
        for(int i = 0 ; i < 20 ; i++ )
            f[i] = i;
        for(int i = 1 ; i <= n ; i++ ){
            int u = A[i] - 'a',v = B[i] - 'a';
            to[u] |= (1 << v);
            int fu = ufind(u),fv = ufind(v);
            if(fu == fv) continue;
            f[fu] = fv;
        }
        int ans = 40;
        for(int i = 0 ; i < 20 ; i++ )
            if(i == ufind(i)) --ans;
        memset(dp,0,sizeof(dp));
        dp[0] = 1;
        int maxi = 0;
        for(int s = 0 ; s < (1 << 20) ; s++ ){
            if(!dp[s]) continue;
            int cnt = 0;
            for(int i = 0 ; i < 20 ; i++ ){
                int u = (1 << i);
                if(s & u) ++cnt;
                if(s & to[i]) continue;
                dp[s | u] = 1;
            }
            maxi = max(maxi,cnt);
        }
        printf("%d\n", ans - maxi);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <string>
#include <vector>
#include <ctime>
#include <queue>
#include <cmath>
#include <set>
#define CLR(a,v)        memset(a,v,sizeof(a))
#define ReadFile(file)  freopen(file,"r",stdin)
#define WriteFile(file) freopen(file,"w",stdout)
using namespace std;
typedef long long       ll;
typedef pair<int,int>   pii;
typedef unsigned int    uint;
typedef unsigned long long    ull;

const double eps = 1e-6;
const double PI  = acos(-1.0);
const double EPS = eps;
const double pi  = PI;
const int N = 1e2+10;

struct Point{
	double x,y;
	Point(){}
	Point(const Point& Val){x=Val.x;y=Val.y;}
	Point(double x,double y):x(x),y(y){}
	void set(double x,double y){
		this->x = x;this->y = y;
	}
	void read(){
		scanf("%lf%lf",&x,&y);
	}
	void print(char end[]){
		if(end==NULL) end[0]='\0';
		printf("%.6f %.6f%s",x,y,end);
	}
	Point rot90(){
		return Point(-y,x);
	}
	Point operator + (const Point& Val)const{
		return Point(x+Val.x, y+Val.y);
	}
	Point operator - (const Point& Val)const{
		return Point(x-Val.x, y-Val.y);
	}
	Point operator * (double Val)const{
		return Point(x*Val, y*Val);
	}
	Point operator / (double Val)const{
		return (*this) * (1.0/Val);
	}
};
typedef Point Vec;
istream& operator >> (istream &io, Point& p){
	io >> p.x >> p.y;
	return io;
}
ostream& operator << (ostream &io, Point& p){
	io << "(" << (fabs(p.x-0)<eps?0:p.x) << "," << (fabs(p.y-0)<eps?0:p.y) << ")" ;
	return io;
}

//--------向量运算---------
Vec PtoV(Point a,Point b){
	// 两点 所示 向量
	return Vec(b.x - a.x , b.y - a.y );
}
double dMult(Vec a,Vec b){
	// 点乘
	return (a.x*b.x) + (a.y*b.y) ;
}
double xMult(Vec a,Vec b){
	// 叉积，有向面积|a||b|形成的平行四边形
	return a.x*b.y-a.y*b.x;
}
double VecMod(Vec a){
	// 模
	return sqrt(dMult(a,a));
}
double VecMod2(Vec a){
	// 模平方
	return dMult(a,a);
}
double Corner2V(Vec a,Vec b){
	//两向量夹角 返回弧度 debuged
	return fabs( acos( dMult(a,b)/VecMod(a)/VecMod(b) ) );
}
Vec VecUnit(Vec a){
	// a的单位向量
	return a / VecMod(a);
}
Vec VRotate(Vec v,double alph){
	// 获得v向量的逆时针旋转alph角度的向量
	double sa = sin(alph),ca = cos(alph);
	return Vec(v.x*ca - v.y*sa , v.x*sa + v.y*ca);
}
   Point PRotate(Point p,Point o,double alph){
	// wait for debug...
	return Point(o+VRotate(PtoV(o,p),alph));
}
Vec GetVV(Vec v){
	// 获得v向量的垂直向量 wait for test ...
	return VRotate(v,pi/2);
}
Point ShadowPOnLine(Point p,Point a,Point b){
	// p在直线|ab|上的垂足
	Vec ab = PtoV(a,b) , ap = PtoV(a,p);
	Vec alph = VecUnit(ab) * dMult(ab,ap) / VecMod(ab);
	return a + alph;
}
vector<Point> LineCrossCircle(Point a,Point b,Point o,double r){
	// 直线与圆的交点
	vector<Point> ret;
	Point t = ShadowPOnLine(o,a,b); // o到直线|ab|的垂足
	Vec ot = PtoV(o,t);
	if(VecMod(ot)-r>eps)return ret; // 没有交点
	if(fabs(VecMod(ot)-r)<eps){ // 如果相切
		ret.push_back(t);
		return ret;
	}
	double lr = sqrt(r*r-VecMod2(ot));
	Vec ta = t + VecUnit(PtoV(t,a))*lr , tb = t + VecUnit(PtoV(t,b))*lr;
	ret.push_back(ta);
	ret.push_back(tb);
	return ret;
}

vector<Point> PointTangentCircle(Point p,Point o,double r){
	// 圆外一点作两个切线 返回切点
	double x2 = VecMod2(p-o);
	double d2 = x2 - r*r;
	vector<Point> ret;
	if(d2 < -eps)return ret; // 点在圆内
	if(r <= eps){ // 圆退化为点
		ret.push_back(o);
		ret.push_back(o);
		return ret;
	}
	d2 = max(d2,0.);
	Point q1 = o + (p-o) * (r*r/x2);
	Point q2 = (p-o).rot90() * (-r*sqrt(d2) / x2);
	ret.push_back(q1 - q2);
	ret.push_back(q1 + q2);
	return ret;
	//double x2 = (p - c).abs2(); // x * x + y * y
	//double d2 = x2 - r * r;
	//vector<Point> ret;
	//if (d2 < -EPS)
	//	return ret;
	//if (r <= EPS) {
	//	ret.push_back(c);
	//	ret.push_back(c);
	//	return ret;
	//}
	//d2 = max(d2, 0.);
	//Point q1 = c + (p - c) * (r * r / x2);
	//Point q2 = (p - c).rot90() * (-r * sqrt(d2) / x2);
	//ret.push_back(q1 - q2);
	//ret.push_back(q1 + q2);
	//return ret;

	//vector<Point> ret;
	//Vec po = PtoV(p,o);
	//if(VecMod(po)-r < eps) return ret;
	//if(fabs(VecMod(po)-r) < eps){
	//	ret.push_back(p);
	//	return ret;
	//}
	//double alph = asin(r/VecMod(po));
	//cout << "alpha===>" << alph*180/pi << "  r=>" << r << "  |po|=>" << VecMod(po) << endl;
	//cout << "circle o==>" << o << " p===>" << p << endl;
	//cout << "|p,T2|==>" << VRotate(VecUnit(po),alph) * sqrt(VecMod2(po)+r*r) << endl;
	//cout << "单位向量|p.T2|" << VRotate(VecUnit(po),alph) << "  长度|pT2|" << sqrt(VecMod2(po)+r*r) << endl;
	//
	//ret.push_back(p + VRotate(VecUnit(po),alph) * sqrt(VecMod2(po)+r*r));
	//ret.push_back(p + VRotate(VecUnit(po),2*pi-alph) * sqrt(VecMod2(po)+r*r));
	//return ret;

	//Vec pt = VecUnit(VRotate(po,asin(r/VecMod(po))))*sqrt(VecMod2(po)+r*r);
	//ret.push_back(p+pt);
	//Point tot = ShadowPOnLine(p+pt,p,o);
	//ret.push_back(tot + PtoV(tot,o));
	//return ret;
}
bool POnSeg(Point p, Point a, Point b){
	// 点在线段上
	if(fabs(xMult(PtoV(a,b), PtoV(a,p))) > eps)return false;
	if(min(a.x,b.x) > p.x || p.x > max(a.x,b.x))return false;
	if(min(a.y,b.y) > p.y || p.y > max(a.y,b.y))return false;
	return true;
}

double PDisLine(Point p,Point a, Point b){
	// p点到直线|ab| 的距离
	return VecMod(ShadowPOnLine(p,a,b) - p);
}
//--------向量运算---------End

void debug_function(){
	Point h(25,45),j(30,30),i(15,35),k(5,45);
	//cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(9);
	Point aaa(0,0), bbb(0,5), ppp(0,-1);
	cout << "p in |ab| ? => " << POnSeg(ppp,aaa,bbb) << endl;

	cout << "π:" << pi << "\t\tπ checked" << endl;
	cout << i << h << j << "\tio checked" << endl;
	cout << Corner2V(PtoV(i,h),PtoV(i,j))*(180/pi) << "\t\t\tCorner2V() checked" << endl;
	i.set(0,0);k.set(-10,4);
	cout << VRotate(PtoV(i,k),pi/2) << " " << PtoV(i,k) << PtoV(i,Point(-4,-10)) << "VRotate() checked" << endl;
	Point p(10,2) , a(-6,6) , b(10,-10);
	cout << ShadowPOnLine(p,a,b) << "\t\t\tShadowPOnLine() checked" << endl;

	double r = 6.64;
	vector<Point> CP = LineCrossCircle(a,b,Point(0,0),r);
	cout << "cross point:" << CP.size() << " ";
	for(int i = 0 ; i < CP.size() ; i++) cout << CP[i] << " " ;
	cout << "\tchecked" << endl;

	p.set(10,2); r = 6.64;
	vector<Point> CT = PointTangentCircle(p,Point(0,0),r);
	cout << "tangent point:" << CT.size() << " ";
	for(int i = 0 ; i < CT.size() ; i++) cout << CT[i] << " " ;
	cout << endl;

	exit(0);
}

Point p,s;
double vp,vs,r , sita;
bool check(double t){
	double len_or = VecMod(p);
	Point e(len_or * cos(sita+t*vp/len_or) , len_or * sin(sita+t*vp/len_or)); // 终点
	//printf("t:%lf (%lf,%lf) \t\t",t,e.x,e.y);
	vector<Point> ccp;
	ccp = LineCrossCircle(s,e, Point(0,0), r);
	if(ccp.size() != 2 || (!POnSeg(ccp[0], s, e) && !POnSeg(ccp[1], s, e)) ){
		//cout << "| |len = " << VecMod(e-s) << endl;
		return vs*t > VecMod(e-s); // 如果没有交点路径就是直线
	}
	vector<Point> ttp1 = PointTangentCircle(s,Point(0,0),r);
	if( PDisLine(ttp1[0],s,e) > PDisLine(ttp1[1],s,e) )
		swap(ttp1[0],ttp1[1]);
	double l1 = VecMod(PtoV(s,ttp1[0]));

	vector<Point> ttp2 = PointTangentCircle(e,Point(0,0),r);
	if( PDisLine(ttp2[0],s,e) > PDisLine(ttp2[1],s,e) )
		swap(ttp2[0],ttp2[1]);
	double l2 = VecMod(PtoV(e,ttp2[0]));

	double alph = Corner2V(PtoV(Point(0,0),ttp1[0]) , PtoV(Point(0,0),ttp2[0]));
	//cout << "tangent:" <<  ttp1[0] << " " << ttp2[0] << endl;
	//cout << "|-|alph = " << alph << ", " << VecMod( PtoV(s,ttp1[0]) )   << "," << VecMod( PtoV(e,ttp2[0]) ) << endl;
	return VecMod( PtoV(s,ttp1[0]) )
		+  VecMod( PtoV(e,ttp2[0]) )
		+ alph * r < vs*t;
}
int main(){
	ios::sync_with_stdio(false);
	//debug_function();
	//freopen("d:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\por\\20130820\\20130820\\in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	//cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2);
	//cout << fixed << setprecision(2) << (*it).first << endl;
	while(cin >> p >> vp >> s >> vs >> r){
		//cout << p << vp << s << vs << " " << r << endl;
		//check(9.584544103);exit(0);
		sita = acos(p.x/VecMod(p));
		if(p.y<0)sita = -sita; // 跨过了180度

		double  left = 0, right = 1e+10;
		while( fabs(left-right) > 1e-12 ){
			double mid = (left+right)*0.5;
 			if(check(mid))
				right = mid;
			else
				left = mid;
		}
		cout << fixed << setprecision(9) << left << endl;
	}
	return 0;
}