A. Blackslex and Password

time limit per test

1 second

memory limit per test

256 megabytes

Blackslex is designing a log-in system for Gean Dev and discovered that most users use weak passwords.

To resolve this issue, he posed the following conditions, dependent on two variables k and x, for all passwords. Each password is a string s of length n satisfying these properties.

  • s uses only the first k lowercase letters of the English alphabet.
  • For every pair of indices 1≤i<j≤n such that (j−i) is divisible by x, the letters si and sj are different.

Find the smallest integer n such that no valid string of length n exists.

Input

The first line contains a single integer t (1≤t≤500) --- the number of test cases.

The first and only line of each test case contains two integers k and x (1≤k≤26, 1≤x≤15).

Output

For each test case, output the minimal n.

Example

Input

Copy

复制代码

3

2 1

3 2

1 5

Output

Copy

复制代码

3

7

6

Note

For the first test case, there are no valid strings of length n=3. For n=2, one such valid example is ab. Note that the only pair (i,j) that (j−i) is divisible by x=1 and 1≤i<j≤n for n=2 is (1,2).

For the second test case, there are no valid strings of length n=7. For n=6, one such valid example is aabccb. Note that all pairs (i,j) that (j−i) is divisible by x=2 and 1≤i<j≤n for n=6 include (1,3), (1,5), (2,4), (2,6), (3,5), and (4,6).

For the third test case, there are no valid strings of length n=6. For n=5, one such valid example is aaaaa. Note that there are no pairs (i,j) that (j−i) is divisible by x=5 and 1≤i<j≤n for n=5.

解题说明:此题是一道数学题,找规律能发现输出k*x+1。求出来满足有效字符串的最大的n,将其+1即可,让每个字符连续出现x次,答案即为k*x+1。

cpp 复制代码
#include<stdio.h>
int main()
{
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++)
	{
		int k, x;
		scanf("%d %d", &k, &x);
		printf("%d\n", 1 + k * x);
	}
	return 0;
}
相关推荐
xx~t2 小时前
嵌入式——Linux软件编程——网络1
linux·c语言·网络·vscode·网络协议
羚尔5 小时前
C语言数组
c语言·开发语言
老当益壮梁奶奶8 小时前
Linux软件编程学习笔记(十一):深入浅出 TCP 协议与 Socket 编程实践
linux·c语言·笔记·学习·tcp/ip
Navigator_Z9 小时前
LeetCode //C - 1223. Dice Roll Simulation
c语言·算法·leetcode
Patrick在香港10 小时前
Python 拉取 C&SD 官方 API:香港 2022 年已跨过“超老龄线“,而抚养比正在爬回 1961
android·c语言·python·数据分析·时序数据库·数据可视化·香港
彷徨而立11 小时前
【C/C++】多线程读写普通 int 变量的一些问题(二)
c语言·c++
luj_176811 小时前
毒素驱动的生物自毁机制探析
服务器·c语言·开发语言·经验分享·算法
Brilliantwxx2 天前
【C语言】 初入嵌入式C语言复习(基础+进阶面试题)
c语言·开发语言
wuminyu2 天前
深入剖析 Panama Off-heap 的性能损耗与开销
java·linux·c语言·jvm·c++
rhythm-ring2 天前
宏定义续行符 \ 的使用与踩坑
c语言·c++