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.

RatneshTiwari3 | 24 |

AnmolPassi | 20 |

Swords | 20 |

baranwalsuraj96 | 17 |

tarun711 | 16 |

Bishnu Dev Panda | 727 |

yk12 | 512 |

DevMittal | 472 |

okayboss | 458 |

VijethaShastri | 431 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4921 |

Quandray | 4547 |

Login to report an issue on this page.