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;
}
相关推荐
HABuo8 小时前
【linux文件系统】磁盘结构&文件系统详谈
linux·运维·服务器·c语言·c++·ubuntu·centos
2401_8589368813 小时前
【Linux C 编程】标准 IO 详解与实战:从基础接口到文件操作实战
linux·c语言
季明洵15 小时前
C语言实现单链表
c语言·开发语言·数据结构·算法·链表
浅念-15 小时前
C语言编译与链接全流程:从源码到可执行程序的幕后之旅
c语言·开发语言·数据结构·经验分享·笔记·学习·算法
爱吃生蚝的于勒16 小时前
【Linux】进程信号之捕捉(三)
linux·运维·服务器·c语言·数据结构·c++·学习
The森16 小时前
Linux IO 模型纵深解析 01:从 Unix 传统到 Linux 内核的 IO 第一性原理
linux·服务器·c语言·经验分享·笔记·unix
C++ 老炮儿的技术栈17 小时前
Qt 编写 TcpClient 程序 详细步骤
c语言·开发语言·数据库·c++·qt·算法
wangjialelele18 小时前
Linux下的IO操作以及ext系列文件系统
linux·运维·服务器·c语言·c++·个人开发
wengqidaifeng20 小时前
数据结构(三)栈和队列(上)栈:计算机世界的“叠叠乐”
c语言·数据结构·数据库·链表
VekiSon20 小时前
Linux内核驱动——设备树原理与应用
linux·c语言·arm开发·嵌入式硬件