Let's say you're on facebook.com/<your friend's tag here>/friends

Buttons pop up that allow you to add each person as a friend, or tell you that you're already friends with certain people. How would that query work? I can understand how it would display the list of friends, but how would it also know whether you're friends with the person or not?

If I have personId 10, and I'm looking at personId 11's friend list, how would the query look that would get me whether or not I'm friends with each person in the friends list?