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;
}
相关推荐
c++之路34 分钟前
C/C++ 全链路编译工具汇总
c语言·开发语言·c++
凡人叶枫1 小时前
Effective C++ 条款02:宁可以编译器替换预处理器
java·linux·c语言·开发语言·c++
周杰伦fans1 小时前
AutoCAD2016经典模式不见了-设置回14版本前的经典工作空间
服务器·c语言·前端
caimouse2 小时前
Reactos 第 5 章 进程与线程 — 5.1 概述
c语言·windows·架构
你疯了抱抱我3 小时前
【STM32】配置vscode+C工具链+Cortex-Debug开发环境,IC:STM32F411CEU6
c语言·vscode·stm32
FFZero13 小时前
[mpv脚本系统] (五) C层系统调用的实现: mpv client通信机制
c语言·音视频
大阳1233 小时前
ARM.9(RGBLCD,PWM)
c语言·开发语言·汇编·单片机·嵌入式硬件·pwm·rgblcd
csdndeyeye4 小时前
从Ctrl+C/V到一键填充:AI投简历工具实测
c语言·开发语言·自动化·秋招·ai助手·网申·ai投简历
某风吾起4 小时前
C语言总结
c语言·开发语言
weixin_447640065 小时前
[GPU运算]cuda调用
c语言·gpu算力