# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
from bisect import bisect_right as br
from types import GeneratorType
def bootstrap(f,stack=[]):
def wrappedfunc(*args,**kwargs):
if stack:
return f(*args,**kwargs)
else:
to = f(*args,**kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
else:
if len(stack):
stack.pop()
if not stack:
break
to = stack[-1].send(to)
return to
return wrappedfunc
mod = 10**9+7
fac = [1]
for ii in range(1,10**5+1):
fac.append((fac[-1]*ii)%mod)
fac_in = [pow(fac[-1],mod-2,mod)]
for ii in range(10**5,0,-1):
fac_in.append((fac_in[-1]*ii)%mod)
fac_in.reverse()
def comb(a,b):
if a < b:
return 0
return (fac[a]*fac_in[a-b]*fac_in[b])%mod
@bootstrap
def find(l,r,val,inde):
if l >= r:
return 1
x = inde[val][br(inde[val],r)-1]
return (comb(r-l,x-l)*find(l,x-1,val,inde)*find(x+1,r,val+1,inde))%mod
def main():
for case in range(1,int(input())+1):
n = int(input())
v = list(map(int,input().split()))
inde = [[] for _ in range(n+1)]
for ind,i in enumerate(v):
inde[i].append(ind)
if v[0] != 1:
ans = 0
else:
for i in range(1,n):
if v[i] > v[i-1]:
if v[i]-v[i-1] != 1:
ans = 0
break
else:
ans = find(0,n-1,1,inde)
print'Case #{}: {}'.format(case,ans)
# Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self,file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))
self.newlines = b.count(b"\n")+(not b)
ptr = self.buffer.tell()
self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd,self.buffer.getvalue())
self.buffer.truncate(0),self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self,file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s:self.buffer.write(s.encode("ascii"))
self.read = lambda:self.buffer.read().decode("ascii")
self.readline = lambda:self.buffer.readline().decode("ascii")
sys.stdin,sys.stdout = IOWrapper(sys.stdin),IOWrapper(sys.stdout)
input = lambda:sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
IyBieSB0aGUgYXV0aG9yaXR5IG9mIEdPRCAgIGF1dGhvcjogbWFuaGFyIHNpbmdoIHNhY2hkZXYgIwoKaW1wb3J0IG9zLHN5cwpmcm9tIGlvIGltcG9ydCBCeXRlc0lPLElPQmFzZQpmcm9tIGJpc2VjdCBpbXBvcnQgYmlzZWN0X3JpZ2h0IGFzIGJyCmZyb20gdHlwZXMgaW1wb3J0IEdlbmVyYXRvclR5cGUKCmRlZiBib290c3RyYXAoZixzdGFjaz1bXSk6CiAgICBkZWYgd3JhcHBlZGZ1bmMoKmFyZ3MsKiprd2FyZ3MpOgogICAgICAgIGlmIHN0YWNrOgogICAgICAgICAgICByZXR1cm4gZigqYXJncywqKmt3YXJncykKICAgICAgICBlbHNlOgogICAgICAgICAgICB0byA9IGYoKmFyZ3MsKiprd2FyZ3MpCiAgICAgICAgICAgIHdoaWxlIFRydWU6CiAgICAgICAgICAgICAgICBpZiB0eXBlKHRvKSBpcyBHZW5lcmF0b3JUeXBlOgogICAgICAgICAgICAgICAgICAgIHN0YWNrLmFwcGVuZCh0bykKICAgICAgICAgICAgICAgICAgICB0byA9IG5leHQodG8pCiAgICAgICAgICAgICAgICBlbHNlOgogICAgICAgICAgICAgICAgICAgIGlmIGxlbihzdGFjayk6CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YWNrLnBvcCgpCiAgICAgICAgICAgICAgICAgICAgaWYgbm90IHN0YWNrOgogICAgICAgICAgICAgICAgICAgICAgICBicmVhawogICAgICAgICAgICAgICAgICAgIHRvID0gc3RhY2tbLTFdLnNlbmQodG8pCiAgICAgICAgICAgIHJldHVybiB0bwoKICAgIHJldHVybiB3cmFwcGVkZnVuYwoKbW9kID0gMTAqKjkrNwpmYWMgPSBbMV0KZm9yIGlpIGluIHJhbmdlKDEsMTAqKjUrMSk6CiAgICBmYWMuYXBwZW5kKChmYWNbLTFdKmlpKSVtb2QpCmZhY19pbiA9IFtwb3coZmFjWy0xXSxtb2QtMixtb2QpXQpmb3IgaWkgaW4gcmFuZ2UoMTAqKjUsMCwtMSk6CiAgICBmYWNfaW4uYXBwZW5kKChmYWNfaW5bLTFdKmlpKSVtb2QpCmZhY19pbi5yZXZlcnNlKCkKCmRlZiBjb21iKGEsYik6CiAgICBpZiBhIDwgYjoKICAgICAgICByZXR1cm4gMAogICAgcmV0dXJuIChmYWNbYV0qZmFjX2luW2EtYl0qZmFjX2luW2JdKSVtb2QKCkBib290c3RyYXAKZGVmIGZpbmQobCxyLHZhbCxpbmRlKToKICAgIGlmIGwgPj0gcjoKICAgICAgICByZXR1cm4gMQogICAgeCA9IGluZGVbdmFsXVticihpbmRlW3ZhbF0sciktMV0KICAgIHJldHVybiAoY29tYihyLWwseC1sKSpmaW5kKGwseC0xLHZhbCxpbmRlKSpmaW5kKHgrMSxyLHZhbCsxLGluZGUpKSVtb2QKCmRlZiBtYWluKCk6CiAgICBmb3IgY2FzZSBpbiByYW5nZSgxLGludChpbnB1dCgpKSsxKToKICAgICAgICBuID0gaW50KGlucHV0KCkpCiAgICAgICAgdiA9IGxpc3QobWFwKGludCxpbnB1dCgpLnNwbGl0KCkpKQogICAgICAgIGluZGUgPSBbW10gZm9yIF8gaW4gcmFuZ2UobisxKV0KICAgICAgICBmb3IgaW5kLGkgaW4gZW51bWVyYXRlKHYpOgogICAgICAgICAgICBpbmRlW2ldLmFwcGVuZChpbmQpCiAgICAgICAgaWYgdlswXSAhPSAxOgogICAgICAgICAgICBhbnMgPSAwCiAgICAgICAgZWxzZToKICAgICAgICAgICAgZm9yIGkgaW4gcmFuZ2UoMSxuKToKICAgICAgICAgICAgICAgIGlmIHZbaV0gPiB2W2ktMV06CiAgICAgICAgICAgICAgICAgICAgaWYgdltpXS12W2ktMV0gIT0gMToKICAgICAgICAgICAgICAgICAgICAgICAgYW5zID0gMAogICAgICAgICAgICAgICAgICAgICAgICBicmVhawogICAgICAgICAgICBlbHNlOgogICAgICAgICAgICAgICAgYW5zID0gZmluZCgwLG4tMSwxLGluZGUpCiAgICAgICAgcHJpbnQnQ2FzZSAje306IHt9Jy5mb3JtYXQoY2FzZSxhbnMpCgojIEZhc3QgSU8gUmVnaW9uCkJVRlNJWkUgPSA4MTkyCgpjbGFzcyBGYXN0SU8oSU9CYXNlKToKICAgIG5ld2xpbmVzID0gMAoKICAgIGRlZiBfX2luaXRfXyhzZWxmLGZpbGUpOgogICAgICAgIHNlbGYuX2ZkID0gZmlsZS5maWxlbm8oKQogICAgICAgIHNlbGYuYnVmZmVyID0gQnl0ZXNJTygpCiAgICAgICAgc2VsZi53cml0YWJsZSA9ICJ4IiBpbiBmaWxlLm1vZGUgb3IgInIiIG5vdCBpbiBmaWxlLm1vZGUKICAgICAgICBzZWxmLndyaXRlID0gc2VsZi5idWZmZXIud3JpdGUgaWYgc2VsZi53cml0YWJsZSBlbHNlIE5vbmUKCiAgICBkZWYgcmVhZChzZWxmKToKICAgICAgICB3aGlsZSBUcnVlOgogICAgICAgICAgICBiID0gb3MucmVhZChzZWxmLl9mZCxtYXgob3MuZnN0YXQoc2VsZi5fZmQpLnN0X3NpemUsQlVGU0laRSkpCiAgICAgICAgICAgIGlmIG5vdCBiOgogICAgICAgICAgICAgICAgYnJlYWsKICAgICAgICAgICAgcHRyID0gc2VsZi5idWZmZXIudGVsbCgpCiAgICAgICAgICAgIHNlbGYuYnVmZmVyLnNlZWsoMCw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