SP2699 SPP - Recursive Sequence (Version II)

Description

Sequence _(a $ _{i} $ )_ of natural numbers is defined as follows: _a $ _{i} $ = b $ _{i} $_ (for _i k_) where _b $ _{j} $_ and _c $ _{j} $_ are given natural numbers for _1

Input Format

On the first row there is the number _C_ of test cases (equal to about 50). Each test contains four lines: _k_ - number of elements of _(c)_ and _(b)_ (_1

Output Format

Exactly _C_ lines, one for each test case: (_a $ _{m} $_ + _a $ _{m+1} $_ + _a $ _{m+2} $_ + ... + _a $ _{n} $_ ) modulo _p_.