Cognitive underlay amplify-and-forward (AF) two-way relay links require signal-to-interference-and-noise-ratio (SINR) balancing and maximizing strategies. And both secondary-to-primary and primary-to-secondary interference must be taken into consideration. To achieve these goals, we develop several joint distributed beamforming and power allocation algorithms. The development is based on the assumption of the availability of channel state information (CSI) of the relay-transceiver channels and the second-order-statistics (SOS) of all channels. For single-relay and multi-relay systems, a closed-form solution and an exhaustive-search optimal algorithm, respectively, are developed. This optimal algorithm, despite its high computational complexity, serves as a useful benchmark. Moreover, two low-complexity suboptimal algorithms are proposed, both of which compute sub-optimal power allocations and beamformers. A 10-dB SINR improvement by the optimal algorithm and similar gains by both proposed suboptimal algorithms are achievable.Index Terms-Amplify-and-forward relaying, cognitive radio, distributed beamforming, power allocation, second-order statistics of channel gains, SINR balancing, two-way relay, underlay.