Option (D) is correct.
Explanation: Two students are related exactly when they share a house, so R splits A into one class per house that actually has somebody in it:
Red={S1,S3,S6},Blue={S2,S5},Green={S4}
Counting the pairs. Inside a class every student is related to every student of that class, including themselves, and no pair ever crosses between classes. So a class of size k contributes k×k ordered pairs:
3×3=9 (Red),2×2=4 (Blue),1×1=1 (Green)
9+4+1=14 ordered pairs
After the move. If S4 joins Blue, the houses in use become Red ={S1,S3,S6} and Blue ={S2,S4,S5}, and Green has nobody left. An equivalence class is the set of all students related to some particular student, so a house with no students produces no class. Only 2 classes remain. (The pair count would then be 9+9=18.)

Why the other options are tempting:
- (A) 8 counts only the pairs of two different students in the same house: 6 from Red, 2 from Blue, 0 from Green. It drops the six pairs (Si,Si), but every student is in the same house as themselves, so those pairs are in R.
- (B) keeps Green on the list after it has been emptied. A class must contain at least one element; there is no student left to build a Green class from.
- (C) 36=62 treats R as "both are students of this school", relating everybody to everybody. But S1 is in Red and S2 is in Blue, so (S1,S2)∈/R.