// #include C { #include #include #include #include #include // } // #include C++ { #include #include #include #include #include #include #include #include #include #include #include #include #include // } using namespace std; // #typedef { typedef long long int64; typedef unsigned long long uint64; typedef pair PII; typedef pair PCC; typedef pair PLL; typedef pair PDD; // } // #parameter{ #ifdef DEBUG_MODE #define TYPE decltype #define RF(filename) {freopen((filename), "r", stdin);} #define WF(filename) {freopen((filename), "w", stdout);} #define DEBUG printf #else #define TYPE __typeof #define RF(filename) {;} #define WF(filename) {;} #define DEBUG(...) #endif // #define { #define SZ(a) ((int)(a).size()) #define X first #define Y second #define MP make_pair #define L(x) ((x)<<1) #define R(x) ((x)<<1 | 1) #define max3(x, y, z) (max(max((x), (y)), (z))) #define min3(x, y, z) (min(min((x), (y)), (z))) #define BIT(x, i) (((x) >> (i)) & 1) #define ALL(it) (it).begin(), (it).end() #define FILL(__space, __val) memset(__space, __val, sizeof(__space)) #define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo)) #define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++) ///////////////////////////////////////////////////////////// const double PI = acos(-1.0); const double EPS = 1e-6; #define MAX_N 55 #define MAX_M 1005 #define MAXX 0x3f #define UPPER 2147483647LL #define INF ((1 << 30) - 1) #define BINF ((1LL << 62) - 1LL) #define NONE -1 #define NIL 0 // } ///////////////////////////////////////////////////////////// struct Card{ char color; int value; Card(){} Card(char color, int value) :color(color), value(value){} inline bool operator < (const Card &rhs) const{ if (color != rhs.color) return color < rhs.color; return value < rhs.value; } inline bool operator == (const Card &rhs) const{ return color == rhs.color && value == rhs.value; } }; struct Game{ vector cards; // 5 Game(){} Game(vector cards) :cards(cards){} }; vector games; void Setup(){ games.clear(); for (char color = 'A'; color <= 'D'; color++){ for (int value = 1; value <= 10; value++){ vector cards; for (int k = 0; k < 5; k++){ int val = value + k; if (val == 14) val = 1; cards.push_back(Card(color, val)); } sort(ALL(cards)); games.push_back(cards); } } } ///////////////////////////////////////////////////////////// int main(){ RF("input.txt"); //WF("output.txt"); Setup(); int T; scanf("%d%*c", &T); while (T--){ char str[MAX_N]; gets(str); char *ptr = strtok(str, " \n"); vector go; while (ptr != NULL){ char color; int value; sscanf(ptr, "%c%d", &color, &value); go.push_back(Card(color, value)); ptr = strtok(NULL, " \n"); } sort(ALL(go)); int res = 5; for (int z = 0; z < SZ(games);z++){ Game game = games[z]; int a = 0, b = 0; int change = 0; while (a < 5 && b < 5){ if (go[a] == game.cards[b]){ a++, b++; } else if (go[a] < game.cards[b]){ a++, change++; } else b++; } while (a < 5) a++, change++; res = min(res, change); } printf("%d\n", res); } return 0; }