#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for (int i=s;i<=t;i++)
#define pi acos(-1)
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef pair<PII, PII> PPP;
typedef pair<PII, int> PPI;
#define repp(i,s,t) for (int i=s;i>=t;i--)
template<class T> T sqr(T x) {return x*x;}
#define debug(x) cerr<<#x"="<<(x)<<endl;
#define pb(x) push_back(x);
#define ori(x) x-'a'
const LL mod = 1e9 + 7;
const int maxn = 1e6;
LL inv[maxn], p[maxn];
int n, a[10];
LL s[1 << 6];
inline LL C(int n, int m) 
{
	return p[n] * inv[m] % mod * inv[n - m] % mod;
}
inline void update(LL &x, LL y)
{
	x = (x + y) % mod;
}
LL f[20001][1 << 6];
int gao()
{
	LL ans = 0;
	rep(k,0,5)
	{
		memset(f,0,sizeof(f));
		f[0][0] = 1;
		rep(i,1,n)
		rep(mask,0,(1<<5) - 1)
		{
			update(f[i][mask], f[i-1][mask] * (5 - k + s[mask]));
			rep(j,0,5) if ((!((mask >> j) & 1)) && a[j] < i)
				update(f[i][mask | (1 << j)], f[i - (a[j] + 1)][mask] * C(i - 1, a[j]));
		}
		rep(mask,0,(1<<5)-1)
		if (s[mask] == k)
		{
			if (k & 1) update(ans, mod - f[n][mask]);
			else update(ans, f[n][mask]);
		}
	}
	return ans;
}

int main()
{
	p[0] = p[1] = inv[0] = inv[1] = 1;
	rep(i,2,100000) 
	{
		p[i] = p[i-1] * i % mod;
		inv[i] = LL(mod - mod / i) * inv[mod % i] % mod;
	}
	rep(i,2,100000) inv[i] = inv[i-1] * inv[i] % mod;
	rep(i,0,1 << 5) s[i] = __builtin_popcount(i);
	int testdata;
	scanf("%d",&testdata);
	rep(_t,1,testdata)
	{
		printf("Case #%d: ", _t);
		scanf("%d",&n);
		rep(i,0,4) scanf("%d",&a[i]);
		LL ans = gao();
		if (a[0] >= 1)
		{
			a[0]--;
			n--;
			update(ans, mod - gao());
		}
		cout << ans << endl;
	}
}

