The easier way -
if ([% ListHasParentMember(forGridQ,1) %] == 1)
if (SSI GetValue ("S4_r1_c1") == SSI GetValue("S4_r1_c2"))
strErrorMessage = "You can't select the same country as 'Main' and 'Secondary'.";
Where forGridQ is the constructed list in which the selected items of select question are coming(Press F1 in SSI and search for the explanation of this function). Repeat the above code for n number of rows.
There is one more method of doing this using arrays. Let me know if you are interested, I will post that too!