Which Go rank is higher? Players of the traditional board game Go measure their skill in a system of ranks:


Players new to the game are ranked 30th kyū (written 30k) and progress counting down to 1st kyū (written 1k). These are considered the student ranks.
A player may promote from 1st kyū to 1st dan rank (written 1d), and then progress counting up to 7th dan rank (written 7d). These are the master ranks.
Exceptionally skilled players past 7d may promote to the 1st professional dan rank 1p, and progress counting up to 9th professional dan rank (written 9p). This is the highest rank.


In short: ranks are ordered 30k &lt; 29k &lt; ··· &lt; 1k &lt; 1d &lt; 2d &lt; ··· &lt; 7d &lt; 1p &lt; 2p &lt; ··· &lt; 9p.

Task

Given two strings among {30k, …, 1k, 1d, …, 7d, 1p, …, 9p} as input, output the higher rank of the two. (If they are equal, simply output either input.)

(As usual, I/O is flexible — your answer may be a function or a full program, reading input in any reasonable fashion and producing output in any reasonable fashion.)

This is code-golf: the objective is to minimize your code's byte count.

Test cases

(Format: input1 input2   output.)

29k 9k    9k
21k 27k   21k
6d 1p     1p
5d 17k    5d
1k 1d     1d
1d 1d     1d
1d 2d     2d
9p 1d     9p
2d 30k    2d
1p 1k     1p
1d 1p     1p
1p 2d     1p
7p 8p     8p
30k 30k   30k
JavaScript (ES7), 58 bytes

Takes the two strings in currying syntax (a)(b).



a=&gt;b=&gt;(g=s=&gt;parseInt(s)*'_dp'.search(s[1])**3)(a)&gt;g(b)?a:b


Try it online!

How?

The helper function g() translate the input string s into a score.

1) We look for s[1] into the string "_dp". This gives:


1 for a dan rank "xd"
2 for a professional dan rank "xp"
-1 for a kyū rank "xk" or "xxk" because s[1] is either "k" or a digit


2) We cube this result, which leaves 1 and -1 unchanged but gives 8 for a professional dan rank.

3) We multiply by the decimal part of the rank.