This paper considers a multi-pair massive multiple-input multiple-output relaying channel where $K$ single-antenna sources communicate with $K$ single-antenna destinations via the assistance of a decode-and-forward relay equipped with massive antenna arrays. The relay station uses maximum-ratio processing to decode the signals transmitted from the sources and precode the signals before broadcasting to the destinations. To perform maximum-ratio processing, the relay needs to know the channels to the sources and the destination. This is done during the training phase where all sources and destinations send pilot sequences to the relay. We consider a very general case in which the pilot sequences are arbitrary. An exact closed-form expression for the end-to-end spectral efficiency is derived taking into account the imperfect channel estimates with arbitrary power control coefficients. From the spectral efficiency formula, we formulate and propose to solve a max-min fairness power allocation. With this power control scheme, the spectral efficiency improves significantly, compared to the uniform power control. In particular, a simple greedy pilot assignment scheme is proposed to reduce the pilot contamination effect, and hence, improve the system performance under the limitations of training duration.