This page is still under construction.

Parts of this page are still being built. What you see may change.

Not a subsequence

Time limit2sMemory limit256 MB

Summary
Given alphabet size k and string s, find the length of the shortest string over the alphabet that is not a subsequence of s and count such strings modulo 1e9+7.
Level

Medium6 of 10

Topics
Greedy, String, Combinatorics
Solved
No attempts yet

Problem

In this problem, an alphabet of size kk means the first kk characters of the list below.

a, b, c, ..., z, A, B, C, ..., Z, 0, 1, ..., 9

Each test case gives its own kk, and only the alphabet of size kk is considered.

A string t[1..m]t[1..m] is a subsequence of a string s[1..n]s[1..n] if there are indices 1≤i1<i2<⋯<im≤n1 \le i_1 < i_2 < \cdots < i_m \le n with t[1]=s[i1]t[1] = s[i_1], t[2]=s[i2]t[2] = s[i_2], ..., t[m]=s[im]t[m] = s[i_m]. For example, acb is a subsequence of babcaab.

Given a string s[1..n]s[1..n], find the smallest mm for which some string t[1..m]t[1..m] is not a subsequence of ss, then count how many such strings there are. The string tt uses only characters of the alphabet of size kk.

Input

The first line has the number of test cases TT (1≤T≤1001 \le T \le 100). Each of the following lines has the alphabet size kk (1≤k≤621 \le k \le 62) and a string s[1..n]s[1..n] (1≤n≤1061 \le n \le 10^6), separated by a space. ss uses only characters from the list above.

Output

For each test case, print two integers on one line. The first integer is the smallest mm. The second integer is the number of such strings t[1..m]t[1..m] modulo 109+710^9 + 7.

Examples2

  1. Example 1

    Input
    3
    2 abba
    62 0123456789
    3 aabbcbbcbabcbab
    
    Expected output
    3 5
    1 52
    4 7
    
  2. Example 2

    Input
    2
    1 a
    1 aaaaa
    
    Expected output
    2 1
    6 1