아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Secret Santa

시간 제한5초메모리 제한512 MB

요약
각 k에 대해 k-n+a < p(k) < k+a를 만족하는 1부터 n까지의 순열 p의 개수를 10^9+7로 나눈 나머지를 구한다.
난이도

보통10점 중 7점

유형
조합론, 동적 계획법, 수학, 구현
정답자
아직 제출이 없습니다

문제

Every Christmas, members of the Community of Algorithms Enthusiasts send gifts to each other. This tradition is a bit problematic and leads to conflicts, because some members always get more gifts than others. This year the community decided to introduce a coordinated and fair system, known as Secret Santa.

The idea behind Secret Santa is very simple: each member of the community is assigned a person to whom they send a gift. This way each member prepares one gift and gets one gift. It is possible that some member is assigned themselves, then they simply send a gift to themselves.

The community is very enthusiastic about the idea, and now they want to assign who sends a gift to whom. However, they need to keep in mind how the postal system works -- whether a package can be delivered from one town to another depends on how strong the wind is that day.

There are nn members of the community. Each member lives in a different town, and the towns are numbered from 11 to nn. If the wind speed is aa, then a package with a gift can be sent from town kk to town ll if and only if k−n+a\<l\<k+ak-n+a\<l\<k+a.

Your task is to find the number of ways to assign community members so that all can send their gifts the same day, given the wind speed that day. As the number can be very large, you only need to find the value modulo 109+710^9+7.

입력

The first line of input contains the number of test cases zz (1≤z≤101 \leq z \leq 10). The descriptions of the test cases follow.

Each test case consists of a single line containing two integers nn and aa (1≤a≤2001 \leq a \leq 200, 1≤n≤1061 \leq n \leq 10^6, a<na < n), the number of community members and the strength of the wind, respectively.

출력

For each test case output one integer: the number of ways community members can be assigned to each other, modulo 109+710^9+7.

예제1

  1. 예제 1

    입력
    3
    4 2
    5 2
    16 5
    
    예상 출력
    5
    13
    418144253