#include #include using namespace std; using mint = atcoder::modint1000000007; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int t; cin >> t; for (; t--;) { long long n, ag, bg, ac, bc, ap, bp; cin >> n >> ag >> bg >> ac >> bc >> ap >> bp; mint g = mint(ag) / bg, c = mint(ac) / bc, p = mint(ap) / bp; assert(g + c + p == 1); mint ans = (g + c).pow(n) + (g + p).pow(n) + (c + p).pow(n) - 2 * (g.pow(n) + c.pow(n) + p.pow(n)); ans = 1 - ans; cout << ans.val() << "\n"; } }