欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1249B1.Books Exchange (easy version)
Books Exchange (easy version)
The only difference between easy and hard versions is constraints.
There are kids, each of them is reading a unique book. At the end of any day, the -th kid will give his book to the -th kid (in case of the kid will give his book to himself). It is guaranteed that all values of are distinct integers from to (i.e. is a permutation). The sequence doesn't change from day to day, it is fixed.
For example, if and then at the end of the first day the book of the -st kid will belong to the -th kid, the -nd kid will belong to the -th kid and so on. At the end of the second day the book of the -st kid will belong to the -th kid, the -nd kid will belong to the -th kid and so on.
Your task is to determine the number of the day the book of the -th child is returned back to him for the first time for every from to .
Consider the following example: . The book of the -st kid will be passed to the following kids:
- after the -st day it will belong to the -th kid,
- after the -nd day it will belong to the -rd kid,
- after the -rd day it will belong to the -nd kid,
- after the -th day it will belong to the -st kid.
So after the fourth day, the book of the first kid will return to its owner. The book of the fourth kid will return to him for the first time after exactly one day.
You have to answer independent queries.
Input
The first line of the input contains one integer () — the number of queries. Then queries follow.
The first line of the query contains one integer () — the number of kids in the query. The second line of the query contains integers (, all are distinct, i.e. is a permutation), where is the kid which will get the book of the -th kid.
Output
For each query, print the answer on it: integers , where is the number of the day the book of the -th child is returned back to him for the first time in this query.
Samples
6
5
1 2 3 4 5
3
2 3 1
6
4 6 2 1 5 3
1
1
4
3 4 1 2
5
5 1 2 4 3
1 1 1 1 1
3 3 3
2 3 3 2 1 3
1
2 2 2 2
4 4 4 1 4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |