Given two positive integers N and X, where N is the number of total patients and X is the time duration(in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.
Example 1:
Input: N = 4, X = 5
Output: 15
Explaination: The arrival time of the 
patients are 0, 5, 10 and 15 respectively. 
The times when the first three patients 
are checked are respectively 10, 20, 30. 
So the Waiting time is 30 - 15 = 15.
Example 2:
Input: N = 3, X = 10
Output: 0
Explaination: The incoming time of the 
patients are 0, 10 and 20 and the firts 
two patients are finished checking at 10, 
20. So the last patient does not need to 
wait.
Your Task:
You do not need to read input or print anything. Your task is to complete the function waitingTime() which takes N and X as input parameters and returns the waiting time of the last patient.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 100
1 ≤ X ≤ 30

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def waitingTime(self, N, X):

        # code here

Solutions:
class Solution:

	def waitingTime(self, N, X):
		b = (N - 1) * 10 - X * (N - 1)
		if b < 0:
			return 0
		else:
			return b


class Solution:

	def waitingTime(self, N, X):
		for i in range(N):
			if i == N - 1:
				time = i * X
				wating_time = i * 10 - time
				if wating_time < 0:
					return 0
				else:
					return wating_time


class Solution:

	def waitingTime(self, n, x):
		a = (n - 1) * 10
		b = (n - 1) * x
		if b <= 0:
			return a
		elif b > a:
			return 0
		else:
			return a - b


class Solution:

	def waitingTime(self, N, X):
		total_at = 0
		total_pt = 0
		while N > 1:
			total_at += X
			total_pt += 10
			N -= 1
		if total_pt - total_at < 0:
			return 0
		return total_pt - total_at


class Solution:

	def waitingTime(self, N, X):
		k = (N - 1) * 10 - (N - 1) * X
		if k > 0:
			return k
		return 0


class Solution:

	def waitingTime(self, N, X):
		y = (N - 1) * X
		z = (N - 1) * 10
		r = z - y
		if r > 0:
			return r
		else:
			return 0


class Solution:

	def waitingTime(self, N, X):
		p = (N - 1) * 10
		s = p - (N - 1) * X
		if s > 0:
			return s
		else:
			return 0


class Solution:

	def waitingTime(self, N, X):
		total = (N - 1) * 10
		ptime = (N - 1) * X
		res = total - ptime
		if res > 0:
			return res
		else:
			return 0


class Solution:

	def waitingTime(self, N, X):
		if N <= 1:
			return 0
		w = []
		a = [0]
		for i in range(1, N):
			a.append(a[i - 1] + X)
			w.append(i * 10)
		if w[-1] < a[-1]:
			return 0
		return w[-1] - a[-1]


class Solution:

	def waitingTime(self, N, X):
		y = (N - 1) * 10
		m = (N - 1) * X
		if X > 10:
			X = 10
			y = (N - 1) * 10
			m = (N - 1) * X
		return y - m


class Solution:

	def waitingTime(self, N, X):
		if X > 10:
			X = 10
		return abs((N - 1) * X - 10 * (N - 1))


class Solution:

	def waitingTime(self, N, X):
		t = 0
		if N < 1:
			return 0
		w = 0
		for i in range(1, N):
			w += 10
			t += X
		if w - t > 1:
			return w - t
		else:
			return 0


class Solution:

	def waitingTime(self, N, X):
		v1 = (N - 1) * X
		v2 = (N - 1) * 10
		ans = v2 - v1
		if ans > 0:
			return ans
		return 0


class Solution:

	def waitingTime(self, N, X):
		check_time = (N - 1) * 10
		patient_intime = (N - 1) * X
		if X < 10:
			wait_time = check_time - patient_intime
			return wait_time
		else:
			return 0


class Solution:

	def waitingTime(self, n, x):
		if x > 10:
			return 0
		return abs((n - 1) * (10 - x))


class Solution:

	def waitingTime(self, N, X):
		s = (N - 1) * 10
		F = (N - 1) * X
		g = s - F
		if g <= 0:
			return 0
		else:
			return g


class Solution:

	def waitingTime(self, N, x):
		l = []
		for i in range(0, N):
			r = i * x
			d = i * 10
		g = d - r
		if g < 0:
			return 0
		return g


class Solution:

	def waitingTime(self, N, X):
		at = X * (N - 1)
		tt = (N - 1) * 10
		if tt - at < 0:
			return 0
		return tt - at


class Solution:

	def waitingTime(self, N, X):
		a = (N - 1) * X
		c = (N - 1) * 10
		if c - a < 0:
			return 0
		else:
			return c - a


class Solution:

	def waitingTime(self, N, X):
		if X > 10:
			return 0
		else:
			return (N - 1) * (10 - X)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(N, X) = [int(a) for a in input().split()]
		ob = Solution()
		print(ob.waitingTime(N, X))


class Solution:

	def waitingTime(self, N, X):
		if X >= 10:
			return 0
		patient = X * (N - 1)
		doctor = (N - 1) * 10
		wait = doctor - patient
		return wait


class Solution:

	def waitingTime(self, N, X):
		if X >= 10:
			return 0
		wt = 0
		for i in range(1, N):
			wt = wt + (10 - X)
		return wt


class Solution:

	def waitingTime(self, N, X):
		if X >= 10 and N > 1:
			return 0
		if N == 0:
			return 0
		s = 0
		w = 0
		for i in range(1, N):
			w = w + 10
			s = s + X
		return w - s


class Solution:

	def waitingTime(self, N, X):
		arr = (N - 1) * X
		tot = (N - 1) * 10
		if tot - arr > 0:
			return tot - arr
		else:
			return 0


class Solution:

	def waitingTime(self, N, X):
		return max(10 * (N - 1) - X * (N - 1), 0)


class Solution:

	def waitingTime(self, N, X):
		arrival_time = (N - 1) * X
		checking_time = 10 * (N - 1)
		d = checking_time - arrival_time
		if d > 0:
			return d
		else:
			return 0