Given a polynomial represented as poly[] and a value x, compute value of the polynomial for given x. The result should be computed **under modulo 10 ^{9}+7.**

```
Input: poly[] = {2, -6, 2, -1}, x = 3
Output: 5
Output is value of 2x
```^{3} - 6x^{2} + 2x - 1 for x = 3
Input: poly[] = {2, 0, 3, 1}, x = 2
Output: 23
Output is value of 2x^{3} + 3x + 1 for x = 2

Expected time complexity is O(n) where n is number of elements in input array poly[].

**Input:**

First line contains an integer, the number of test cases 'T' Each test case should contain an integer, size of array 'N' in the first line. In the second line Input the integer elements of the poly[] in a single line separated by space. Element X should be inputted in the third line after entering the elements of array.

**Output:**

Print the output in a separate lines

**Constraints:**

1 <= T <= 1000

1 <= N <= 2000

0 <= poly[i] <= 1000

0 <= x <= 1000

**Example:**

Input:

1

4

1 2 0 4

2

Output:

20

Explanation:

There is one test case that represents polynomial 1*x^3 + 2*x^2 + 0*x^1 + 4*x^0. The value of this polynomial for x = 2 is 20.

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.

hardikJain5 | 258 |

CodeBuddy | 250 |

bhatabhi554 | 232 |

Akkki111 | 197 |

clone | 174 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

SumitSingh27 | 1127 |

mazumderrohit8 | 1124 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4591 |

Quandray | 4444 |

Login to report an issue on this page.