Quantum nanodevice can be both a heat engine and a fridge at the same time