I would think that you should be able to unpivot and count the occurrences in ways that your business rules require. Based on my (limited) understanding of your rules, it can, for example, be done like shown below.
If having to manually list the key columns is not an acceptable solution, the only other thought that comes to mind is to write a dynamic query. However, I am a reluctant user of dynamic SQL - so I will defer that to someone else.
CREATE TABLE #tbl(TestId INT, keya CHAR(3), keyb CHAR(3), keyc char(3), keyd CHAR(3))
INSERT INTO #tbl VALUES
SELECT DISTINCT kys,testid
COUNT(*) OVER (PARTITION BY testid,kys) N1,
COUNT(*) OVER (PARTITION BY kys) N2
UNPIVOT (kys FOR k IN (keya, keyb, keyc, keyd))U
WHERE N1 < N2 ORDER BY 1,2
DROP TABLE #tbl
-- Yes, I am indeed a fictional character.