In the year 4242, the language Haskell has evolved so much that it has become an AI. It can solve very challenging problems, in very little time. Humanity is worried that Haskell will take over the world. All hopes remain tied to the Competitive Programming community as they are the expert in shaving milliseconds off code runtime. Haskell creators have found one particular task that if solved faster than Haskell itself, can be used to hack into Haskell's codebase and thus defeat it. The exact details of the task are as follows,


" Calculate the sum, S(N, K) = , for Q queries. Here Fi is ith Fibonacci number defined as: Fi = i if i = 0 or 1 and Fi = Fi-1 + Fi-2 if i >= 2. "


You being a member of the Competitive Programming community are encouraged to make a submission to this task.

-----Input-----

The first line contains a single integer Q, the number of queries.

Each of the next Q lines contain two integers each, Ni and Ki.

-----Output-----

Output Q lines with one integer each. The ith line should contain the value S(Ni, Ki).

-----Constraints-----
- 1 <= Q <= 5*104
- 1 <= N <= 1018
- 1 <= K <= 1018

-----Example-----
Input:
1
1 1
Output:
1

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'mod=10**9+7\ndef fibonacci(n):\n if n < 0:\n  raise ValueError("Negative arguments not implemented")\n return (_fib(n)[0]%mod + mod)%mod;\ndef _fib(n):\n if n == 0:\n  return (0, 1)\n else:\n  a, b = _fib(n // 2)\n  c = (a * (b * 2 - a))%mod\n  d = (a * a + b * b)%mod\n  if n % 2 == 0:\n   return (c, d)\n  else:\n   return (d, c + d)\ndef inv(n):\n return pow(n,mod-2,mod)\ndef brute(n,k):\n ret = 0\n for i in range(0,n+1):\n  ret+=fibonacci(i)*pow(k,i,mod)\n return ret%mod\ndef ans(n,k):\n k%=mod\n a = pow(k,n+1,mod)\n b=(a*k)%mod\n x = a*(fibonacci(n+1))+b*fibonacci(n)-k\n y = inv((k*k+k-1)%mod)\n return ((x*y)%mod+mod)%mod\nfor t in range(0,eval(input())):\n n,k = list(map(int,input().split()))\n print(ans(n,k))'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 17369