You are given two strings s and t, each of length n and consisting of lowercase Latin alphabets. You want to make s equal to t. 

You can perform the following operation on s any number of times to achieve it — 

  * Choose any substring of s and rotate it clockwise once, that is, if the selected substring is s[l,l+1...r], then it becomes s[r,l,l + 1 ... r - 1]. All the remaining characters of s stay in their position. 

For example, on rotating the substring [2,4] , string "abcde" becomes "adbce". 




A string a is a substring of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Find the minimum number of operations required to convert s to t, or determine that it's impossible.

Input

The first line of the input contains a single integer t (1≤ t ≤ 2000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (1≤ n ≤ 2000) — the length of the strings. 

The second and the third lines contain strings s and t respectively.

The sum of n over all the test cases does not exceed 2000.

Output

For each test case, output the minimum number of operations to convert s to t. If it is not possible to convert s to t, output -1 instead.

Example

Input


6
1
a
a
2
ab
ba
3
abc
cab
3
abc
cba
4
abab
baba
4
abcc
aabc


Output


0
1
1
2
1
-1

Note

For the 1-st test case, since s and t are equal, you don't need to apply any operation.

For the 2-nd test case, you only need to apply one operation on the entire string ab to convert it to ba.

For the 3-rd test case, you only need to apply one operation on the entire string abc to convert it to cab.

For the 4-th test case, you need to apply the operation twice: first on the entire string abc to convert it to cab and then on the substring of length 2 beginning at the second character to convert it to cba.

For the 5-th test case, you only need to apply one operation on the entire string abab to convert it to baba.

For the 6-th test case, it is not possible to convert string s to t.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class FRotatingSubstrings {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            String s = in.nextString();
            String t = in.nextString();
            int[] sc = new int[26];
            for (int i = 0; i < n; i++) {
                sc[s.charAt(i) - 'a']++;
            }
            int[] tc = new int[26];
            for (int i = 0; i < n; i++) {
                tc[t.charAt(i) - 'a']++;
            }
            for (int i = 0; i < 26; i++) {
                if (sc[i] != tc[i]) {
                    out.println(-1);
                    return;
                }
            }
            int INF = 11234;
            int[][] dp = new int[n][n];
            dp[n - 1][n - 1] = (s.charAt(n - 1) == t.charAt(n - 1)) ? (0) : INF;
            for (int i = n - 2; i >= 0; i--) {
                dp[i][n - 1] = (s.charAt(i) == t.charAt(n - 1)) ? (n - i - 1) : (dp[i + 1][n - 1] + 1);
            }
            for (int j = 0; j < (n - 1); j++) {
                dp[n - 1][j] = INF;
            }
            int[][] pre = new int[26][n];
            int[][] pret = new int[26][n];
            pre[s.charAt(0) - 'a'][0] = 1;
            pret[t.charAt(0) - 'a'][0] = 1;
            for (int i = 1; i < n; i++) {
                int ch = s.charAt(i) - 'a';
                for (int j = 0; j < 26; j++) {
                    pre[j][i] = pre[j][i - 1];
                }
                pre[ch][i]++;
            }
            for (int i = 1; i < n; i++) {
                int ch = t.charAt(i) - 'a';
                for (int j = 0; j < 26; j++) {
                    pret[j][i] = pret[j][i - 1];
                }
                pret[ch][i]++;
            }
            for (int i = n - 2; i >= 0; i--) {
                for (int j = n - 2; j >= 0; j--) {
                    if (s.charAt(i) == t.charAt(j)) {
                        dp[i][j] = dp[i + 1][j + 1];
                    } else {
                        if (getCount(pre, i + 1, n - 1, t.charAt(j)) > getCount(pret, j + 1, n - 1, t.charAt(j))) {
                            dp[i][j] = Math.min(dp[i + 1][j] + 1, dp[i][j + 1]);
                        } else {
                            dp[i][j] = dp[i + 1][j] + 1;
                        }
                    }
                }
            }
//        dp[0][0] = (s.charAt(0) == t.charAt(0)) ? (0) : 2;
//        for (int i = 1; i < n; i++) {
//            dp[0][i] = (s.charAt(0) == t.charAt(i)) ? (i) : dp[0][i-1] + 1;
//        }
//        for (int i = 1; i < n; i++) {
//            dp[i][0] = (s.charAt(i) == t.charAt(0)) ? (i) : dp[i-1][0] + 1;
//        }
//        for (int i = 1; i < n; i++) {
//            for (int j = 1; j < n; j++) {
//                if (s.charAt(i) == t.charAt(j)) {
//                    dp[i][j] = dp[i-1][j-1];
//                } else {
//                    dp[i][j] = Math.min(dp[i][j-1] + 1, dp[i-1][j] + 1);
//                }
//            }
//        }
//        int ans = dp[n-1][n-1] / 2;
            int ans = dp[0][0];
            if (ans >= INF) {
                ans = -1;
            }
            out.println(ans);
        }

        private int getCount(int[][] pre, int i, int j, char ch) {
            int c = ch - 'a';
            if (i == 0) return pre[c][j];
            return pre[c][j] - pre[c][i - 1];
        }

    }

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

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

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

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}

