import sys, time, random, heapq, math, itertools, copy from collections import deque, Counter, defaultdict from sortedcontainers import SortedSet, SortedList from bisect import bisect, bisect_left, bisect_right import heapq as hq from functools import cache, cmp_to_key def debug(*x):print('debug:',*x, file=sys.stderr) sys.setrecursionlimit(300000) input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 61 - 1 mod = 998244353 dir = [(0, 1), (0, -1), (1, 0), (-1, 0)] T = ii() for _ in range(T): Hc, Ac, Sc, Hg, Ag, Sg = mi() # 死ぬ直前のターンまでスキップ? t = min((Hc-1)//Ag, (Hg-1)//Ac) Hc -= t * Ag Hg -= t * Ac debug(t) debug(Hc, Hg, Ac, Ag) # 水色が後一回で倒れるなら,1/10を耐えた後1/2勝負で勝つ if Hc - Ag <= 0: rest = (Hg-1)//Ac ans = pow(10, -rest, mod) # あと一回まで追い込む if Sc > Sg: # 9/10 + 1/10*1/10*9/10 + ... = 10/11 ans *= 10 * pow(11, -1, mod) ans %= mod elif Sc < Sg: ans *= pow(11, -1, mod) else: ans *= pow(2, -1, mod) else: # 水色が優勢なら,上記の余事象(セルみたい) Hc, Ac, Sc, Hg, Ag, Sg = Hg, Ag, Sg, Hc, Ac, Sc rest = (Hg-1)//Ac ans = pow(10, -rest, mod) # あと一回まで追い込む if Sc > Sg: # 9/10 + 1/10*1/10*9/10 + ... = 10/11 ans *= 10 * pow(11, -1, mod) ans %= mod elif Sc < Sg: ans *= pow(11, -1, mod) else: ans *= pow(2, -1, mod) ans =1 - ans ans %= mod print(ans)