MOD = 1000000007 def count_placements(s): n = len(s) left, right = [0] * n, [0] * n for i in range(n): if s[i] == '<': left[i] = 1 elif s[i] == '>': right[i] = 1 elif s[i] == 'o': left[i] = right[i] = 1 # calculate prefix and suffix sums for i in range(1, n): left[i] += left[i-1] for i in range(n-2, -1, -1): right[i] += right[i+1] # count valid placements count = 0 for i in range(n): if s[i] == '.': if left[i] > 0 and right[i] > 0: count += pow(2, left[i]+right[i]-2, MOD) elif s[i] == '=': if left[i] > 0 and right[i] > 0: count += pow(2, left[i]+right[i]-2, MOD) elif left[i] == 0 and right[i] == 0: count += 1 elif s[i] == '<': if left[i] == 0: count += 1 elif s[i] == '>': if right[i] == 0: count += 1 elif s[i] == 'o': count += 1 return count % MOD # read input T = int(input()) for t in range(1, T+1): s = input().strip() count = count_placements(s) print(f"Case #{t}: {count}")