Given $n$ locked chests and $n$ keys such that each chest is opened by exactly one key and each key opens exactly one chest. Our goal is to determine which key opens each chest. A trial consists of trying to open a chest with a key. Determine the smallest number $p(n)$ such that there exists a procedure that, when followed, ensures we will know the $n$ corresponding chest-key pairs after at most $p(n)$ trials.