#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    vector<int> vec1;
    vector<int> vec2;
    vector<int> vec3;
    bool oo, tt, th;
    for (int i = 0; i < str.size(); i++) {
      if (str[i] == '1') vec1.push_back(i);
      if (str[i] == '2') vec2.push_back(i);
      if (str[i] == '3') vec3.push_back(i);
    }
    int ans = INT_MAX;
    for (auto x : vec1) {
      oo = true;
      tt = th = false;
      int cnt = 1;
      for (int i = x + 1; i < str.size(); i++) {
        if (str[i] == '1') break;
        if (str[i] == '2') tt = true;
        if (str[i] == '3') th = true;
        cnt++;
        if (oo && tt && th) break;
      }
      if (oo && tt && th) ans = min(ans, cnt);
      oo = true;
      tt = th = false;
      cnt = 1;
      for (int i = x - 1; i >= 0; i--) {
        if (str[i] == '1') break;
        if (str[i] == '2') tt = true;
        if (str[i] == '3') th = true;
        cnt++;
        if (oo && tt && th) break;
      }
      if (oo && tt && th) ans = min(ans, cnt);
    }
    for (auto x : vec2) {
      tt = true;
      oo = th = false;
      int cnt = 1;
      for (int i = x + 1; i < str.size(); i++) {
        if (str[i] == '2') break;
        if (str[i] == '1') oo = true;
        if (str[i] == '3') th = true;
        cnt++;
        if (oo && tt && th) break;
      }
      if (oo && tt && th) ans = min(ans, cnt);
      tt = true;
      oo = th = false;
      cnt = 1;
      for (int i = x - 1; i >= 0; i--) {
        if (str[i] == '2') break;
        if (str[i] == '1') oo = true;
        if (str[i] == '3') th = true;
        cnt++;
        if (oo && tt && th) break;
      }
      if (oo && tt && th) ans = min(ans, cnt);
    }
    for (auto x : vec3) {
      th = true;
      oo = tt = false;
      int cnt = 1;
      for (int i = x + 1; i < str.size(); i++) {
        if (str[i] == '3') break;
        if (str[i] == '1') oo = true;
        if (str[i] == '2') tt = true;
        cnt++;
        if (oo && tt && th) break;
      }
      if (oo && tt && th) ans = min(ans, cnt);
      th = true;
      oo = tt = false;
      cnt = 1;
      for (int i = x - 1; i >= 0; i--) {
        if (str[i] == '3') break;
        if (str[i] == '1') oo = true;
        if (str[i] == '2') tt = true;
        cnt++;
        if (oo && tt && th) break;
      }
      if (oo && tt && th) ans = min(ans, cnt);
    }
    if (ans == INT_MAX) ans = 0;
    cout << ans << '\n';
  }
  return 0;
}

### Prompt

Please create a solution in CPP to the following problem:

You are given a string s such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of s such that it contains each of these three characters at least once.

A contiguous substring of string s is a string that can be obtained from s by removing some (possibly zero) characters from the beginning of s and some (possibly zero) characters from the end of s.

Input

The first line contains one integer t (1 ≤ t ≤ 20000) — the number of test cases.

Each test case consists of one line containing the string s (1 ≤ |s| ≤ 200000). It is guaranteed that each character of s is either 1, 2, or 3.

The sum of lengths of all strings in all test cases does not exceed 200000.

Output

For each test case, print one integer — the length of the shortest contiguous substring of s containing all three types of characters at least once. If there is no such substring, print 0 instead.

Example

Input


7
123
12222133333332
112233
332211
12121212
333333
31121


Output


3
3
4
4
0
0
4

Note

Consider the example test:

In the first test case, the substring 123 can be used.

In the second test case, the substring 213 can be used.

In the third test case, the substring 1223 can be used.

In the fourth test case, the substring 3221 can be used.

In the fifth test case, there is no character 3 in s.

In the sixth test case, there is no character 1 in s.

In the seventh test case, the substring 3112 can be used.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    vector<int> vec1;
    vector<int> vec2;
    vector<int> vec3;
    bool oo, tt, th;
    for (int i = 0; i < str.size(); i++) {
      if (str[i] == '1') vec1.push_back(i);
      if (str[i] == '2') vec2.push_back(i);
      if (str[i] == '3') vec3.push_back(i);
    }
    int ans = INT_MAX;
    for (auto x : vec1) {
      oo = true;
      tt = th = false;
      int cnt = 1;
      for (int i = x + 1; i < str.size(); i++) {
        if (str[i] == '1') break;
        if (str[i] == '2') tt = true;
        if (str[i] == '3') th = true;
        cnt++;
        if (oo && tt && th) break;
      }
      if (oo && tt && th) ans = min(ans, cnt);
      oo = true;
      tt = th = false;
      cnt = 1;
      for (int i = x - 1; i >= 0; i--) {
        if (str[i] == '1') break;
        if (str[i] == '2') tt = true;
        if (str[i] == '3') th = true;
        cnt++;
        if (oo && tt && th) break;
      }
      if (oo && tt && th) ans = min(ans, cnt);
    }
    for (auto x : vec2) {
      tt = true;
      oo = th = false;
      int cnt = 1;
      for (int i = x + 1; i < str.size(); i++) {
        if (str[i] == '2') break;
        if (str[i] == '1') oo = true;
        if (str[i] == '3') th = true;
        cnt++;
        if (oo && tt && th) break;
      }
      if (oo && tt && th) ans = min(ans, cnt);
      tt = true;
      oo = th = false;
      cnt = 1;
      for (int i = x - 1; i >= 0; i--) {
        if (str[i] == '2') break;
        if (str[i] == '1') oo = true;
        if (str[i] == '3') th = true;
        cnt++;
        if (oo && tt && th) break;
      }
      if (oo && tt && th) ans = min(ans, cnt);
    }
    for (auto x : vec3) {
      th = true;
      oo = tt = false;
      int cnt = 1;
      for (int i = x + 1; i < str.size(); i++) {
        if (str[i] == '3') break;
        if (str[i] == '1') oo = true;
        if (str[i] == '2') tt = true;
        cnt++;
        if (oo && tt && th) break;
      }
      if (oo && tt && th) ans = min(ans, cnt);
      th = true;
      oo = tt = false;
      cnt = 1;
      for (int i = x - 1; i >= 0; i--) {
        if (str[i] == '3') break;
        if (str[i] == '1') oo = true;
        if (str[i] == '2') tt = true;
        cnt++;
        if (oo && tt && th) break;
      }
      if (oo && tt && th) ans = min(ans, cnt);
    }
    if (ans == INT_MAX) ans = 0;
    cout << ans << '\n';
  }
  return 0;
}

```