Characterization of a prototype imaging calorimeter for the Advanced Particle-astrophysics Telescope from an Antarctic balloon flight and CERN beam test