Solution:
The answer is (C). Note that, if Alice takes 3 envelopes, she cannot be sure of having the 3 pairs of socks she needs: for example the first envelope could contain a white sock, a yellow one and a red one, the second a white one, a yellow one and a green one, and the third a white one, a yellow one and a light blue one, and there would be only two well-matched pairs (a white one and a yellow one).
If Alice takes 4 envelopes, we see that in every case she finds the 3 pairs she needs. Let us call the three (distinct) colors of the socks present in the first envelope A,B and C; let us call D and E the two colors that do not appear in the first envelope. The second envelope must have at least one color in common with the first, say A, of which we then have the pair. If it has no other colors in common, its colors are A,D and E, so with the third envelope we obtain the other two pairs (at least two socks are not A and so they pair up with non-A socks found previously). If the second envelope has at least one other color in common, say B, we also have the pair of that color. It remains to find the third pair: observing that each of the 4 envelopes contains at least one sock of a color different from A and from B, among these socks there must be two of the same color (there are only 3 available colors, namely C,D and E) and then these socks will be the third pair. The minimum number of envelopes required is therefore 4.