A is easy. Drawing to 6-4-3-2 and 5-4-3-2 aren't that different, so you throw the 5

away to avoid the flush draw.
B If you throw the 8 away, you only have six outs to make an 8 or better. If you throw the 6 away, you have nine outs, so that is the better choice.
If you had this hand initially, you might throw the 8 away to give yourself a shot at making a seven. You have three draws to improve and you can also pair one of your cards and not have a flush draw.
Barry