import sys sys.setrecursionlimit(10**6) def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) inf = 10**19 md = 10**9+7 def extgcd(x, md): a, b = 1, 0 while md: a, b = b, (a-x//md*b) x, md = md, x%md return a def gcd(a, b): while b: a, b = b, a%b return a def solve(a, b, s): g = gcd(a, b) if s%g: return 0 a, b, s = a//g, b//g, s//g x = (s*extgcd(a, b))%b y = (s-a*x)//b res = y//a+1 if res < 0: return 0 return res mx = 1000005 for _ in range(II()): pp = LI() y = pp[-1] a, b, c = sorted(pp[:3]) ans = 0 for i in range(mx): if i*c > y: break ans += solve(a, b, y-i*c) ans %= md print(ans)