As a general rule, you can make payments at any time. In the case of pillar 3a, however, you cannot pay in more than the maximum annual amount set by the Federal Council. Your payment must reach the recipient by no later than 31 December of any year in order to qualify for deduction from your income tax the following year. If you pay in at the beginning of the year, you earn interest over the entire year on the amount paid.
And, if you can afford to invest the pillar-3a maximum amount, you can invest up to the same amount in pillar-3b, provided you have the necessary funds available.