t = int(input())

for task in range(t):
    s, k = input().split()
    k = int(k)
    s = [x == "+" for x in s]
    def flip(p):
        if p + k > len(s):
            return False
        for i in range(p, p + k):
            s[i] = not s[i]
        return True
    n = 0
    for i, x in enumerate(s):
        if not x:
            if flip(i):
                n += 1
            else:
                print("Case #{}: IMPOSSIBLE".format(task + 1))
                break
    else:
        print("Case #{}: {}".format(task + 1, n))

254ed5913fe4dfc083ca7dbe7e0f3a9af7fd0469
<mask token>

<mask token>
for task in range(t):
    s, k = input().split()
    k = int(k)
    s = [(x == '+') for x in s]

    def flip(p):
        if p + k > len(s):
            return False
        for i in range(p, p + k):
            s[i] = not s[i]
        return True
    n = 0
    for i, x in enumerate(s):
        if not x:
            if flip(i):
                n += 1
            else:
                print('Case #{}: IMPOSSIBLE'.format(task + 1))
                break
    else:
        print('Case #{}: {}'.format(task + 1, n))

t = int(input())
for task in range(t):
    s, k = input().split()
    k = int(k)
    s = [(x == '+') for x in s]

    def flip(p):
        if p + k > len(s):
            return False
        for i in range(p, p + k):
            s[i] = not s[i]
        return True
    n = 0
    for i, x in enumerate(s):
        if not x:
            if flip(i):
                n += 1
            else:
                print('Case #{}: IMPOSSIBLE'.format(task + 1))
                break
    else:
        print('Case #{}: {}'.format(task + 1, n))

t = int(input())

for task in range(t):
    s, k = input().split()
    k = int(k)
    s = [x == "+" for x in s]
    def flip(p):
        if p + k > len(s):
            return False
        for i in range(p, p + k):
            s[i] = not s[i]
        return True
    n = 0
    for i, x in enumerate(s):
        if not x:
            if flip(i):
                n += 1
            else:
                print("Case #{}: IMPOSSIBLE".format(task + 1))
                break
    else:
        print("Case #{}: {}".format(task + 1, n))
