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.

vamsikrishna55 | 122 |

UrGuru | 117 |

Vagesh Verma | 112 |

chaolinyu | 96 |

Akhil varma | 93 |

abducodes | 634 |

harshtyagi36 | 302 |

highway_to_hell | 252 |

rajeswarii | 248 |

Akhil varma | 246 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.