Terrace Martin, one the producers and songwriters behind Kendrick and Rihanna’s collab “LOYALTY.” has revealed how the track came about.

In an interview with The Fader, Martin explained the genesis of the track — and how it all began with a sample from Bruno Mars’ 24K Magic.

“‘LOYALTY.’ came about because I was working with Rapsody and 9th Wonder. 9th Wonder has a producer under him named Khrysis, who sent me a record to play on. It was a Bruno Mars sample off 24K Magic. I was like, ‘Whoa, that sounds crazy.’ I said, ‘I wanna replay it, reverse it, change the key, add a third harmony — do all these things to it. But still make it sound just like the sample, but with a different edge.'”

Martin revealed that as soon as Kendrick heard the beat, he made up his mind over who he wanted to lay the vocals.

“I turned the sample around, set it up, and then hit Sounwave. From there, me, Sounwave, and DJ Dahi got in the studio and started to put drums on that motherfucker. Right there, on my mama, Kendrick said: “Imma get Rihanna on this.” That day. Right when the drums started, he looked at me saying, “Aye, I’m gonna get Rihanna on this record.”

Martin also spoke about working with producers Dahi and Sounwave on the track: “I’ve never worked with anybody in my life that was as fast and perfect as Dahi. I’m talking about every idea — experimental. Every idea — new… Then Sounwave listens to it, and Sounwave knows how to make songs out of everything, you know, so he’s like the cherry on top.”