Geek loves to play with toys a lot. Once his parents bought him a new toy, that **'R', ****‘B’ **and **‘G’ **characters**.** His parents gave him a task, that was to make a string of size **'n**'. Each character of the string is either **‘R’, ‘B’ **or** ‘G’**. In the final string there needs to be at least '**r'** number of **‘R’**, at least '**b'** number of **‘B’** and at least '**g'** number of **‘G’** (such that r + g + b <= n). Geek being busy with some other work requested for your help to find the count of all possible strings that can be formed using the given number of characters.

Examples:

```
Input : n = 4, r = 1,
b = 1, g = 1.
Output: 36
No. of 'R' >= 1,
No. of ‘G’ >= 1,
No. of ‘B’ >= 1 and
(No. of ‘R’) + (No. of ‘B’) + (No. of ‘G’) = n
then following cases are possible:
1. RBGR and its 12 permutation
2. RBGB and its 12 permutation
3. RBGG and its 12 permutation
Hence answer is 36.
```

**Input:**

First line of the input contains an integer **T** denoting the number of test cases. Then **T** test cases follow. The only line of each test case contains four space separated integers denoting the values of **'n', 'r', 'g' **&** 'b'** respectively.

**Output:**

For each test print a single line containg an integer denoting the count of number of all possible strings.

**Constraints:**

1<=T<=100

1<=N<=20

1<=r+g+b<=N

**Example:
Input:**

2

4 1 1 1

4 2 0 1

36

22

Author: harshitsidhwa

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

cs_abhi | 102 |

PiyushPandey4 | 100 |

codefundo | 95 |

kya_bolti_public | 93 |

masterishaan19 | 74 |

PiyushPandey4 | 916 |

john_wick | 765 |

ASWATHAMA | 565 |

UsfShilpa | 556 |

akhyasharma01 | 547 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.