A. Olympiad Date

time limit per test

1 second

memory limit per test

256 megabytes

The final of the first Olympiad by IT Campus "NEIMARK" is scheduled for March 1, 2025. A nameless intern was tasked with forming the date of the Olympiad using digits --- 01.03.2025.

To accomplish this, the intern took a large bag of digits and began drawing them one by one. In total, he drew nn digits --- the digit aiai was drawn in the ii-th turn.

You suspect that the intern did extra work. Determine at which step the intern could have first assembled the digits to form the date of the Olympiad (the separating dots can be ignored), or report that it is impossible to form this date from the drawn digits. Note that leading zeros must be displayed.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤201≤n≤20).

The second line of each test case contains nn integers aiai (0≤ai≤90≤ai≤9) --- the numbers that the intern pulled out in chronological order.

Output

For each test case, output the minimum number of digits that the intern could pull out. If all the digits cannot be used to make a date, output the number 00.

Example

Input

Copy

复制代码

4

10

2 0 1 2 3 2 5 0 0 1

8

2 0 1 2 3 2 5 0

8

2 0 1 0 3 2 5 0

16

2 3 1 2 3 0 1 9 2 1 0 3 5 4 0 3

Output

Copy

复制代码
9
0
8
15

解题说明:水题,直接遍历数组判断是否找出所需要的所有数字即可。

cpp 复制代码
#include <iostream>
#include<algorithm>
using namespace std;

int main()
{
	int  t = 1;
	cin >> t;
	while (t--) 
	{
		int n = 0;
		cin >> n;
		int a[21];
		int mp[11] = {0};
		int ans = 0;
		for (int i = 1; i <= n; i++)
		{
			cin >> a[i];
			mp[a[i]]++;
			if (mp[0] >= 3 && mp[1] >= 1 && mp[2] >= 2 && mp[3] >= 1 && mp[5] >= 1 && ans == 0)
			{
				ans = i;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
相关推荐
deng-c-f1 分钟前
C/C++内置库函数(5):值/引用传递、移动构造、以及常用的构造技巧
开发语言·c++
qq_310658512 分钟前
mediasoup源码走读(十)——producer
服务器·c++·音视频
一招定胜负3 分钟前
逻辑回归调优三板斧:参数调整、阈值设定、数据集平衡
算法·机器学习·逻辑回归
豆约翰6 分钟前
Z字形扫描ccf
java·开发语言·算法
Tipriest_8 分钟前
C++ Python使用常用库时如何做欧拉角 ⇄ 四元数转换
c++·python·四元数·欧拉角
Salt_072810 分钟前
DAY 35 文件的规范拆分和写法
python·算法·机器学习
hweiyu0011 分钟前
数据结构:后缀自动机
数据结构
小尧嵌入式11 分钟前
C语言中的面向对象思想
c语言·开发语言·数据结构·c++·单片机·qt
风筝在晴天搁浅15 分钟前
代码随想录 109.冗余连接Ⅱ
算法
业精于勤的牙16 分钟前
浅谈:算法中的斐波那契数(三)
算法·职场和发展