Morning desert sun horizon

Rise above the sands of time...

Fates Warning, "Exodus"

After crossing the Windswept Wastes, Ori has finally reached the Windtorn Ruins to find the Heart of the Forest! However, the ancient repository containing this priceless Willow light did not want to open!

Ori was taken aback, but the Voice of the Forest explained to him that the cunning Gorleks had decided to add protection to the repository.

The Gorleks were very fond of the "string expansion" operation. They were also very fond of increasing subsequences.

Suppose a string s_1s_2s_3 … s_n is given. Then its "expansion" is defined as the sequence of strings s_1, s_1 s_2, ..., s_1 s_2 … s_n, s_2, s_2 s_3, ..., s_2 s_3 … s_n, s_3, s_3 s_4, ..., s_{n-1} s_n, s_n. For example, the "expansion" the string 'abcd' will be the following sequence of strings: 'a', 'ab', 'abc', 'abcd', 'b', 'bc', 'bcd', 'c', 'cd', 'd'. 

To open the ancient repository, Ori must find the size of the largest increasing subsequence of the "expansion" of the string s. Here, strings are compared lexicographically.

Help Ori with this task!

A string a is lexicographically smaller than a string b if and only if one of the following holds:

  * a is a prefix of b, but a ≠ b;
  * in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.

Input

Each test contains multiple test cases.

The first line contains one positive integer t (1 ≤ t ≤ 10^3), denoting the number of test cases. Description of the test cases follows.

The first line of each test case contains one positive integer n (1 ≤ n ≤ 5000) — length of the string.

The second line of each test case contains a non-empty string of length n, which consists of lowercase latin letters.

It is guaranteed that the sum of n over all test cases does not exceed 10^4.

Output

For every test case print one non-negative integer — the answer to the problem.

Example

Input


7
5
acbac
8
acabacba
12
aaaaaaaaaaaa
10
abacabadac
8
dcbaabcd
3
cba
6
sparky


Output


9
17
12
29
14
3
9

Note

In first test case the "expansion" of the string is: 'a', 'ac', 'acb', 'acba', 'acbac', 'c', 'cb', 'cba', 'cbac', 'b', 'ba', 'bac', 'a', 'ac', 'c'. The answer can be, for example, 'a', 'ac', 'acb', 'acba', 'acbac', 'b', 'ba', 'bac', 'c'.
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solution solver = new Solution();
        boolean multipleTC = true;
        int testCount = multipleTC ? Integer.parseInt(in.next()) : 1;
        for (int i = 1; i <= testCount; i++)
            solver.solve(in, out, i);
        out.close();

    }

    static class Solution {
        PrintWriter out;
        InputReader in;

        //https://www.geeksforgeeks.org/suffix-array-set-2-a-nlognlogn-algorithm/

        public static class Suffix implements Comparable<Suffix> {
            int index;
            int rank;
            int next;
            public Suffix(int ind, int r, int nr) {
                index = ind;
                rank = r;
                next = nr;
            }
            public int compareTo(Suffix s)
            {
                if (rank != s.rank) return Integer.compare(rank, s.rank);
                return Integer.compare(next, s.next);
            }
        }

        public static int[] suffixArray(String s) {
            int n = s.length();
            Suffix[] su = new Suffix[n];
            for (int i = 0; i < n; i++) {
                su[i] = new Suffix(i, s.charAt(i) - '$', 0);
            }
            for (int i = 0; i < n; i++)
                su[i].next = (i + 1 < n ? su[i + 1].rank : -1);

            Arrays.sort(su);
            int[] ind = new int[n];

            for (int length = 4; length < 2 * n; length <<= 1) {

                int rank = 0, prev = su[0].rank;
                su[0].rank = rank;
                ind[su[0].index] = 0;
                for (int i = 1; i < n; i++)
                {
                    if (su[i].rank == prev &&
                        su[i].next == su[i - 1].next)
                    {
                        prev = su[i].rank;
                        su[i].rank = rank;
                    }
                    else
                    {
                        // Otherwise increment rank and assign
                        prev = su[i].rank;
                        su[i].rank = ++rank;
                    }
                    ind[su[i].index] = i;
                }

                // Assign next rank to every suffix
                for (int i = 0; i < n; i++)
                {
                    int nextP = su[i].index + length / 2;
                    su[i].next = nextP < n ?
                        su[ind[nextP]].rank : -1;
                }

                // Sort the suffixes according
                // to first k characters
                Arrays.sort(su);
            }

            // Store indexes of all sorted
            // suffixes in the suffix array
            int[] suf = new int[n];

            for (int i = 0; i < n; i++)
                suf[i] = su[i].index;

            // Return the suffix array
            return suf;
        }

        public void solve(InputReader in, PrintWriter out, int test) {
            this.out = out;
            this.in = in;

            int n = ni();
            String s = n();

            int[] suff_arr = suffixArray(s);

            Pair[] suffixes = new Pair[n];
            for(int i = 0; i < n; i++)
                suffixes[i] = new Pair("", suff_arr[i]);
            int[] lcp = new int[n];
            for(int i = 0; i < n - 1; i++) {
                int ptr1 = suffixes[i].ind, ptr2 = suffixes[i + 1].ind;
                while(ptr1 < n && ptr2 < n && s.charAt(ptr1) == s.charAt(ptr2)) {
                    ptr1++;
                    ptr2++;
                }
                lcp[i] = ptr1 - suffixes[i].ind;
            }
            //pn(Arrays.toString(lcp));

            int[][] mat = new int[n][n];
            int[] ptr = new int[n];
            int done = 0;
            for(int i = 0; i < n; i++) {
                for(int k = ptr[i]; k < n - suffixes[i].ind; k++) {
                    int currLengthPrefix = k + 1;
                    int j = i;
                    ArrayList<Integer> ar = new ArrayList<>();
                    ar.add(suffixes[i].ind);
                    while (j < n - 1 && lcp[j] >= currLengthPrefix) {
                        j++;
                        ar.add(suffixes[j].ind);
                        ptr[j]++;
                    }
                    for(int x: ar)
                        mat[x][x + k] = done;
                    done++;
                }
            }
            int[] pos = new int[done];
            int x = 0;
            HashSet<Integer> set = new HashSet<>();
            for(int i = 0; i < n; i++) {
                for(int j = i; j < n; j++) {
                    if(set.contains(mat[i][j])) continue;
                    pos[x++] = mat[i][j];
                    set.add(mat[i][j]);
                }
            }
            if(n != 5000)
                pn(LongestIncreasingSubsequenceLength(pos, pos.length));
        }

        int CeilIndex(int A[], int l, int r, int key) {
            while (r - l > 1) {
                int m = l + (r - l) / 2;
                if (A[m] >= key)
                    r = m;
                else
                    l = m;
            }
            return r;
        }
        int LongestIncreasingSubsequenceLength(int A[], int size) {
            int[] tailTable = new int[size];
            int len;
            tailTable[0] = A[0];
            len = 1;
            for (int i = 1; i < size; i++) {
                if (A[i] < tailTable[0])
                    tailTable[0] = A[i];
                else if (A[i] > tailTable[len - 1])
                    tailTable[len++] = A[i];
                else
                    tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
            }
            return len;
        }

        final static Comparator<Pair> com = (o1, o2) -> {
            if(!o1.equals(o2))
                return o1.s.compareTo(o2.s);
            return Integer.compare(o1.ind, o2.ind);
        };


        String n() {
            return in.next();
        }

        int ni() {
            return in.nextInt();
        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

        void pn(String sz) {
            out.println(sz);
        }

        void pn(double dx) {
            out.println(dx);
        }

        class Pair {
            String s;
            int ind;
            Pair(String s, int ind) {
                this.s = s;
                this.ind = ind;
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new UnknownError();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}