Synthesize Policies for Transfer and Adaptation across Tasks and Environments