I have a problem with text wrapping around two figures side by side, each of which has a different height. Look at the required template below.

Currently I placed two pictures with minipage environment. But how can I combine it with the wrapfigure environment to get the required result? Or maybe there are other solutions?
Currently i use this simple code:
\documentclass{article}
\usepackage{wrapfig}
\usepackage{xcolor}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{figure}[h]
\begin{minipage}[t]{0.5\linewidth}
\centering
\textcolor{blue}{\rule{3cm}{3cm}}
\caption{A}
\label{fig:A}
\end{minipage}
\begin{minipage}[t]{0.5\linewidth}
\centering
\textcolor{blue}{\rule{5cm}{8cm}}
\caption{B}
\label{fig:B}
\end{minipage}
\end{figure}
\lipsum[2]
\end{document}
