MOD = 10**9 + 7 def count_placements(s): n = len(s) leftmost = [0] * n rightmost = [0] * n for i in range(n): if s[i] == '<': leftmost[i] = 0 if i == 0 else leftmost[i - 1] + 1 elif s[i] == '>': rightmost[n - i - 1] = 0 if i == 0 else rightmost[n - i] + 1 has_gold = any(c == 'o' for c in s) if not has_gold: return 0 gold_spots = [i for i in range(n) if s[i] == 'o'] for i in range(n): if s[i] == '=': leftmost[i] = min(leftmost[i], rightmost[i]) rightmost[i] = leftmost[i] num_choices = 1 for i in range(n): if s[i] == '.': choices = min(leftmost[i], rightmost[i]) + 1 num_choices = (num_choices * choices) % MOD return num_choices t = int(input()) for i in range(t): s = input().strip() ans = count_placements(s) print("Case #{}: {}".format(i + 1, ans))