We consider an extension of standard General Relativity in which the Hilbert-Einstein action is replaced by an arbitrary function of the Ricci scalar, nonmetricity, torsion, and the trace of the matter energy-momentum tensor. By construction, the action involves a non-minimal coupling between matter and geometry. The field equations of the model are obtained, and they lead to the nonconservation of the matter energy-momentum tensor. A thermodynamic interpretation of the nonconservation of the energy-momentum tensor is also developed in the framework of the thermodynamics of the irreversible processes in open systems. The Newtonian limit of the theory is considered, and the generalized Poisson equation is obtained in the low velocity and weak fields limits. The nonmetricity, the Weyl vector, and the matter couplings generate an effective gravitational coupling in the Poisson equation. We investigate the cosmological implications of the theory for two different choices of the gravitational action, corresponding to an additive and a multiplicative algebraic structure of the function $f$, respectively. We obtain the generalized Friedmann equations, and we compare the theoretical predictions with the observational data. \te{We find that the cosmological models can give a good descriptions of the observations up to a redshift of $z=2$, and, for some cases, up to a redshift of $z=3$.