Note : This question carries $100$ $points$
CodeLand is celebrating a festival by baking cakes! In order to avoid wastage, families follow a unique way of distributing cakes.
For $T$ families in the locality, $i$-th family (1 <= $i$ <= $T$) has $N$ members. They baked $S$ slices of cakes. The smallest member of the family gets $K$ slices of cakes. Each family has a lucky number of $R$ and they agree to distribute the slices such that the member gets $R$ times more slices than the member just smaller than them. Since the family is busy in festival preparations, find out if the number of slices would be sufficient for the family or not. Also, find how many extra slices they have or how many slices are they short of.
Also, the locality is kind and believes in sharing. So, you also need to determine if each family would have sufficient slices if families shared their cakes among each other!

-----Input :-----
- First line of input will have a single integer $T$ i.e. the number of families in the locality
- For next $T$ lines, each line will describe one family through 4 integers i.e. $S$, $N$, $K$, $R$ separated by spaces

-----Output-----
- First $T$ lines of output will show if slices are enough for the family or not, followed by extra or required slices. For example, if slices are sufficient, the output would be $POSSIBLE$ $10$ which implies 10 slices are extra. If slices are insufficient, the output would be $IMPOSSIBLE$ $15$ which implies 15 slices are required to fulfill the requirement.
- Last line of output would be $IMPOSSIBLE$ or $POSSIBLE$ depending on whether each family would get enough slices after sharing.

-----Constraints:-----
- 1 ≤ $T$ ≤ 50
- 1 ≤ $N$ ≤ 15
- 1 ≤ $S$ ≤ 10^9
- 1 ≤ $K$ ≤ 5
- 1 ≤ $R$ ≤ 5

-----Sample Input:-----
5
100 4 2 2
100 4 3 2
100 4 3 3
200 4 4 2
10 3 2 2

-----Sample Output:-----
POSSIBLE 70
POSSIBLE 55
IMPOSSIBLE 20
POSSIBLE 140
IMPOSSIBLE 4
POSSIBLE

-----Explanation-----
For the first home, the youngest member has got 2 slices, the one older than them gets 2 times more slices, and so forth. So, first home needs 2 + 4 + 8 + 16 = 30 slices. But since they made 100, they have 70 extra, hence we print 'POSSIBLE 70'.
Doing the same for other houses, we find 20 + 4 = 24 slices extra are required so that all families have enough slices. In this case we have 70 + 55 + 140 = 265 extra slices which is > 24, so we print 'POSSIBLE' in last line.

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
(extra, less) = (0, 0)
for _ in range(int(input())):
	(sli, mem, sma, luc) = list(map(int, input().split()))
	total = sma
	t = sma
	while mem > 1:
		t *= luc
		total += t
		mem -= 1
	if total <= sli:
		extra += sli - total
		print('POSSIBLE', sli - total)
	else:
		less += total - sli
		print('IMPOSSIBLE', total - sli)
if extra >= less:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


import math
import random
import re
import os
import sys

def cake(c):
	k = c[2]
	t = c[3]
	s = 0
	for i in range(c[1]):
		s += k
		k *= t
	if s > c[0]:
		s -= c[0]
		c.append('IMPOSSIBLE')
		c.append(-s)
	else:
		s = c[0] - s
		c.append('POSSIBLE')
		c.append(s)
	return list(str(c[4]) + str(c[5]))

def main():
	n = int(input())
	c = [[]] * n
	res = []
	m = []
	cou = 0
	for i in range(n):
		c[i] = list(map(int, input().rstrip().split()))
		res.append(cake(c[i]))
	for i in range(len(c)):
		print(*c[i][-2:-1], end=' ')
		print(abs(*c[i][-1:]))
		m.append(*c[i][-1:])
	cou = sum(m)
	if cou > 0:
		print('POSSIBLE')
	else:
		print('IMPOSSIBLE')
	return 0

def __starting_point():
	main()
__starting_point()


s1 = 0
s2 = 0
for _ in range(int(input())):
	l = []
	l = list(map(int, input().split()))
	s = int(l[0])
	n = int(l[1])
	k = int(l[2])
	r = int(l[3])
	if r != 1:
		s -= k * (r ** n - 1) // (r - 1)
	else:
		s -= k * n
	if s >= 0:
		print('POSSIBLE', s)
	else:
		print('IMPOSSIBLE', abs(s))
	if s > 0:
		s1 += s
	else:
		s2 += abs(s)
if s1 >= s2:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


sTot = 0
for _ in range(int(input())):
	(s, n, k, r) = map(int, input().split())
	if r == 1:
		sn = k * n
	else:
		sn = k * (r ** n - 1) / (r - 1)
	if sn <= s:
		print('POSSIBLE', int(s - sn))
		sTot += s - sn
	else:
		print('IMPOSSIBLE', int(sn - s))
		sTot -= sn - s
if sTot >= 0:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


over = 0
missing = 0
for i in range(int(input())):
	(s, n, k, r) = list(map(int, input().split()))
	totalSlicesNeeded = k
	currNeeded = k
	for i in range(n - 1):
		currNeeded *= r
		totalSlicesNeeded += currNeeded
	if totalSlicesNeeded > s:
		missing += totalSlicesNeeded - s
		print(f'IMPOSSIBLE {totalSlicesNeeded - s}')
	else:
		over += s - totalSlicesNeeded
		print(f'POSSIBLE {s - totalSlicesNeeded}')
if over >= missing:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


(p, ip) = (0, 0)
for _ in range(int(input())):
	(s, n, k, r) = map(int, input().split())
	sm = 0
	while n != 0:
		sm += k
		k = r * k
		n -= 1
	if s - sm >= 0:
		print('POSSIBLE', s - sm)
		p += s - sm
	else:
		print('IMPOSSIBLE', abs(s - sm))
		ip += abs(s - sm)
if p >= ip:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


from math import pow
check_possible = 0
for _ in range(int(input())):
	(s, n, k, r) = map(int, input().split())
	if r > 1:
		total_slices = k * (pow(r, n) - 1) / (r - 1)
	else:
		total_slices = k * n
	left_slices = s - total_slices
	check_possible += left_slices
	if left_slices >= 0:
		print('POSSIBLE', int(left_slices))
	else:
		print('IMPOSSIBLE', int(-left_slices))
if check_possible >= 0:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


(c, d) = (0, 0)
for _ in range(int(input())):
	(s, n, k, r) = input().split()
	(s, n, k, r) = (int(s), int(n), int(k), int(r))
	(sum, g, x) = (0, k, 0)
	a = k
	for i in range(int(n - 1)):
		a = a * r
		g = g + a
	if g < s:
		x = s - g
		print('POSSIBLE', x)
		c = c + x
	else:
		x = g - s
		print('IMPOSSIBLE', x)
		d = d + x
if c > d:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


(total, possible, impossible) = (0, 0, 0)
for i in range(int(input())):
	(N, S, K, R) = list(map(int, input().split()))
	total = total + N
	points = K
	sum = K
	for j in range(S - 1):
		points = points * R
		sum += points
	if sum <= N:
		possible = possible + N - sum
		print('POSSIBLE', N - sum)
	else:
		impossible = impossible + sum - N
		print('IMPOSSIBLE', sum - N)
if possible >= impossible:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


t = int(input())
grandsum = 0
while t:
	l = list(map(int, input().strip().split()))
	s = l[0]
	n = l[1]
	k = l[2]
	r = l[3]
	res = k
	for i in range(1, n):
		k = k * r
		res = res + k
	if res <= s:
		print('POSSIBLE', str(s - res))
		grandsum += s - res
	else:
		print('IMPOSSIBLE', str(abs(s - res)))
		grandsum -= abs(s - res)
	t -= 1
if grandsum < 0:
	print('IMPOSSIBLE')
else:
	print('POSSIBLE')


t = int(input())
extra = 0
required = 0
while t > 0:
	(s, n, k, r) = list(map(int, input().split()))
	sum1 = k
	pro = k
	for i in range(1, n):
		pro = pro * r
		sum1 += pro
	z = s - sum1
	if z >= 0:
		extra += z
		print('POSSIBLE', z)
	else:
		z = z * -1
		required += z
		print('IMPOSSIBLE', z)
	t -= 1
if extra - required >= 0:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


t = int(input())
sum = 0
for _ in range(t):
	(s, n, k, r) = map(int, input().split())
	if r == 1:
		k = s - n * k
	else:
		k = s - k * ((r ** n - 1) // (r - 1))
	sum += k
	if k < 0:
		print('IMPOSSIBLE', -k)
	else:
		print('POSSIBLE', k)
if sum < 0:
	print('IMPOSSIBLE')
else:
	print('POSSIBLE')


t = int(input())
sum1 = 0
list2 = list()
list3 = list()
list4 = list()
while t > 0:
	(s, n, k, r) = input().split()
	s = int(s)
	list3.append(s)
	n = int(n)
	k = int(k)
	r = int(r)
	list1 = []
	sum1 = s + sum1
	ans = k
	while n > 0:
		list1.append(ans)
		ans = ans * r
		n -= 1
	m = sum(list1)
	list2.append(m)
	z = s - m
	list4.append(z)
	t -= 1
x = sum(list2)
for i in list4:
	if i > 0:
		print('POSSIBLE', i)
	else:
		print('IMPOSSIBLE', -i)
if x > sum1:
	print('IMPOSSIBLE')
else:
	print('POSSIBLE')


x = int(input())
li = []
for i in range(x):
	temp = 0
	(s, n, k, r) = map(int, input().split())
	for j in range(n):
		if j == 0:
			temp += k
		else:
			k = k * r
			temp += k
	if temp > s:
		print('IMPOSSIBLE {0}'.format(temp - s))
		li.append(s - temp)
	else:
		print('POSSIBLE {0}'.format(s - temp))
		li.append(s - temp)
if sum(li) >= 0:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


poss = 0
imposs = 0
for _ in range(int(input())):
	(s, n, k, r) = list(map(int, input().split()))
	a = [0] * n
	a[0] = k
	for i in range(1, n):
		a[i] = a[i - 1] * r
	if sum(a) <= s:
		x = s - sum(a)
		print('POSSIBLE ' + str(x))
		poss = poss + x
	else:
		y = abs(s - sum(a))
		print('IMPOSSIBLE ' + str(y))
		imposs = imposs + y
if imposs <= poss:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


fam = int(input())
(extra, req) = (0, 0)
for i in range(fam):
	(s, n, k, r) = list(map(int, input().split()))
	if r > 1:
		sm = k * (r ** n - 1) // (r - 1)
	else:
		sm = k * n
	if sm <= s:
		print('POSSIBLE', s - sm)
		extra += s - sm
	else:
		print('IMPOSSIBLE', abs(s - sm))
		req += abs(s - sm)
if extra >= req:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


def fun1(S, N, K, R):
	total = K
	for _ in range(1, N):
		K = K * R
		total += K
	return S - total
final = 0
T = int(input())
for i in range(T):
	(S, N, K, R) = map(int, input().split())
	slices_required = fun1(S, N, K, R)
	if slices_required >= 0:
		print('POSSIBLE', end=' ')
		print(slices_required)
	else:
		print('IMPOSSIBLE', end=' ')
		print(abs(slices_required))
	final += slices_required
if final >= 0:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


value = 0
val = int(input())
for i in range(val):
	(s, n, a, b) = list(map(int, input().split()))
	sum = a
	total = a
	n -= 1
	while n:
		sum = sum * b
		total += sum
		n -= 1
	if s >= total:
		print('POSSIBLE ', s - total)
		value += s - total
	else:
		print('IMPOSSIBLE ', total - s)
		value -= total - s
if value >= 0:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


import math
try:
	t = int(input())
	tot = 0
	out = []
	while t:
		(s, n, k, r) = map(int, input().split())
		kin = k
		a = []
		a.append(k)
		for i in range(n - 1):
			k = k * r
			a.append(k)
		k = sum(a)
		if s > k:
			s = s - k
			out.append(f'POSSIBLE {s}')
			tot += s
		else:
			s = k - s
			out.append(f'IMPOSSIBLE {s}')
			tot -= s
		t -= 1
	for i in out:
		print(i)
	if tot > 0:
		print('POSSIBLE')
	else:
		print('IMPOSSIBLE')
except EOFError as e:
	print(end='')


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
mod = 1000000007

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())

def printIn(ob):
	return stdout.write(str(ob) + '\n')

def powerLL(n, p):
	result = 1
	while p:
		if p & 1:
			result = result * n % mod
		p = int(p / 2)
		n = n * n % mod
	return result

def myCode():
	ext = 0
	short = 0
	(s, n, k, r) = In()
	share = k
	dist = k
	for i in range(n - 1):
		dist = dist * r
		share = share + dist
	if share <= s:
		ext = s - share
		print('POSSIBLE ' + str(ext))
	else:
		short = share - s
		print('IMPOSSIBLE ' + str(short))
	return (ext, short)

def main():
	extra = 0
	shortage = 0
	for t in range(I()):
		(e, s) = myCode()
		extra += e
		shortage += s
	if extra >= shortage:
		print('POSSIBLE')
	else:
		print('IMPOSSIBLE')

def __starting_point():
	main()
__starting_point()


list1 = []
t = int(input())
for i in range(t):
	(s, n, k, r) = list(map(int, input().split()))
	p = 0
	for i in range(n):
		a = r ** i
		p = p + a * k
	c = s - p
	list1.append(c)
	if s >= p:
		print('POSSIBLE {0}'.format(c))
	else:
		print('IMPOSSIBLE {0}'.format(abs(c)))
s = 0
for j in range(len(list1)):
	s += list1[j]
if s == 0 or s > 0:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


t = int(input())
po = 0
ne = 0
for i in range(t):
	(s, n, k, r) = list(map(int, input().split()))
	sum = 0
	for j in range(n):
		sum = sum + k
		k = k * r
	if s >= sum:
		remaining_slices = s - sum
		print('POSSIBLE', remaining_slices)
		po = po + remaining_slices
	else:
		remaining_slices = sum - s
		print('IMPOSSIBLE', remaining_slices)
		ne = ne + remaining_slices
if po >= ne:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


try:
	t = int(input())
	required = 0
	avaliable = 0
	for i in range(t):
		(s, n, k, r) = list(map(int, input().strip().split(' ')))
		total = k
		for i in range(n - 1):
			total += k * r
			k = k * r
		if total > s:
			print('IMPOSSIBLE', total - s)
			required += total - s
		else:
			print('POSSIBLE', s - total)
			avaliable += s - total
	if required <= avaliable:
		print('POSSIBLE')
	else:
		print('IMPOSSIBLE')
except:
	pass


T = int(input())
if T >= 1 and T <= 50:
	pos = 0
	imp = 0
	for i in range(0, T):
		(s, n, k, r) = [int(x) for x in input().split()][:4]
		if (n >= 1 and n <= 15) and (s >= 1 and s <= 10000000000) and (k >= 1 and k <= 5) and (r >= 1 and r <= 5):
			total = k
			for j in range(0, n - 1):
				k = k * r
				total = total + k
			mid = s - total
			if total > s:
				imp = imp + abs(mid)
				print('IMPOSSIBLE {}'.format(abs(mid)))
			else:
				pos = pos + abs(mid)
				print('POSSIBLE {}'.format(abs(mid)))
	if pos > imp:
		print('POSSIBLE')
	else:
		print('IMPOSSIBLE')


n = int(input())
sum1 = 0
sum2 = 0
for i in range(0, n):
	arr = []
	arr = list(map(int, input().split()))
	lst = [arr[2]]
	for i in range(1, arr[1]):
		a = lst[-1] * arr[3]
		lst.append(a)
	total = sum(lst)
	diff = arr[0] - total
	if diff >= 0:
		sum1 = sum1 + diff
		print('POSSIBLE ' + str(diff))
	else:
		sum2 = sum2 + diff
		print('IMPOSSIBLE ' + str(abs(diff)))
check = sum1 + sum2
if check >= 0:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')