As a part of the Grand Duchy of Lithuania and the Polish–Lithuanian Commonwealth