Consider the recurrence relation for $n\ge 1$ given by
\begin{equation} \tag{1} \label{1}
A_{n+1}=\alpha A_n+\beta A_{n-1}+f_n,
\end{equation}
where $\alpha$ and $\beta$ are constants (not dependent on $n$), and $f_n$ is a given function of $n$. Eqn.~\eqref{1} is to be solved
either for specified $A_0$, $A_1$, or two constraints of the form
\begin{align}\tag{2}\label{2}
\sum_{n=1}^{\infty} c_nA_n&=h_n, \\
\sum_{n=1}^{\infty} d_nA_n&=g_n.
\end{align}
We can write Eqn.~\eqref{1} as
\begin{equation} \tag{3} \label{3}
\begin{bmatrix} A_{n+1} \\ A_n \end{bmatrix}=T\begin{bmatrix} A_n \\ A_{n-1} \end{bmatrix}+\begin{bmatrix} f_n \\ 0 \end{bmatrix},
\end{equation}
where
\begin{equation*}
T=\begin{bmatrix} \alpha & \beta \\ 1 & 0 \end{bmatrix}.
\end{equation*}
First consider the case where the eigenvalues of $T$ are distinct, and given by
\begin{align} \tag{4} \label{4}
\lambda_1&=\frac{\alpha-\sqrt{\alpha^2+4\beta}}{2}, \\
\lambda_2&=\frac{\alpha+\sqrt{\alpha^2+4\beta}}{2}.
\end{align}
We deal with the case of repeated eigenvalues where $\beta=-\alpha^2/4$, and $\lambda_1=\lambda_2=\alpha/2$ later by taking appropriate limits.
Since the eigenvalues are distinct, $T$ is diagonalizable, and can be written as
\begin{equation} \tag{5} \label{5}
T=\lambda_1 P_1+\lambda_2 P_2,
\end{equation}
where $P_1$ and $P_2$ are projections given by
\begin{align*}
P_1&=\frac{T-\lambda_2 I}{\lambda_1-\lambda_2}, \\
P_2&=\frac{T-\lambda_1 I}{\lambda_2-\lambda_1}.
\end{align*}
Thus, we have
\begin{equation} \tag{6} \label{6}
T^n=\lambda_1^n P_1+\lambda_2^n P_2.
\end{equation}
We now have
\begin{align} \tag{7} \label{7}
\begin{bmatrix} A_{n+1} \\ A_n \end{bmatrix}&=T^n\begin{bmatrix} A_1 \\ A_0 \end{bmatrix}+\sum_{k=1}^{n-1}T^{n-k}\begin{bmatrix} f_k \\ 0 \end{bmatrix}
+\begin{bmatrix} f_n \\ 0 \end{bmatrix} \notag \\
&=(\lambda_1^n P_1+\lambda_2^n P_2)\begin{bmatrix} A_1 \\ A_0 \end{bmatrix}+\sum_{k=1}^{n-1}(\lambda_1^{n-k} P_1+\lambda_2^{n-k} P_2)
\begin{bmatrix} f_k \\ 0 \end{bmatrix}+\begin{bmatrix} f_n \\ 0 \end{bmatrix},
\end{align}
which leads to the explicit formula
\begin{equation} \tag{8} \label{8}
A_n=\frac{1}{\lambda_2-\lambda_1}\left[(\lambda_2^n-\lambda_1^n)A_1-\lambda_1\lambda_2\left(\lambda_2^{n-1}-\lambda_1^{n-1}\right)A_0
+\sum_{k=1}^{n-1} \left(\lambda_2^{n-k}-\lambda_1^{n-k}\right)f_k\right].
\end{equation}
If $f_n=f_0$ is a constant, Eqn.~\eqref{8} simplifies to
\begin{equation} \tag{9} \label{9}
A_n=\frac{1}{\lambda_2-\lambda_1}\left[(\lambda_2^n-\lambda_1^n)A_1-\lambda_1\lambda_2\left(\lambda_2^{n-1}-\lambda_1^{n-1}\right)A_0
+\left(\frac{\lambda_2(\lambda_2^{n-1}-1)}{\lambda_2-1}-\frac{\lambda_1(\lambda_1^{n-1}-1)}{\lambda_1-1}\right)f_0\right].
\end{equation}
If $\lambda_1=1$, say, then by taking the limit in the above equation, we get
\begin{equation} \tag{10} \label{10}
A_n=\frac{1}{\lambda_2-1}\left[(\lambda_2^n-1)A_1-\lambda_2\left(\lambda_2^{n-1}-1\right)A_0
+\left(\frac{\lambda_2(\lambda_2^{n-1}-1)}{\lambda_2-1}-(n-1)\right)f_0\right].
\end{equation}
In case the constraints in Eqn.~\eqref{2} are imposed in place of prescribed values for $A_0$ and $A_1$, then we determine $A_0$ and $A_1$
by substituting the solution given by Eqn.~\eqref{8} into Eqns.~\eqref{2}.
The solution for the case where the eigenvalues of $T$ are repeated is obtained by taking the limit $\lambda_2\rightarrow \lambda_1$ in
Eqn.~\eqref{8}, and setting $\lambda_1=\alpha/2$ as
\begin{equation} \tag{11} \label{11}
A_n=\left(\frac{\alpha}{2}\right)^{n-1}\left[nA_1-\frac{\alpha(n-1)A_0}{2}\right]+\sum_{k=1}^{n-1}(n-k)f_k\left(\frac{\alpha}{2}\right)^{n-k-1}.
\end{equation}
If $f_n=f_0$ is a constant, Eqn.~\eqref{11} simplifies to
\begin{align*}
A_n&=\left(\frac{\alpha}{2}\right)^{n-1}\left[nA_1-\frac{\alpha(n-1)A_0}{2}\right]+\frac{4\left[2^n+(n-1)\alpha^n-2n\alpha^{n-1}\right]f_0}{(\alpha-2)^22^n},
&& (\alpha\ne 2), \\
&=nA_1-(n-1)A_0+\frac{n(n-1)f_0}{2}, && (\alpha=2).
\end{align*}
As examples, consider the following:
- The Fibonacci sequence defined by $A_{n+1}=A_n+A_{n-1}$ with $A_0=0$, $A_1=1$, so that $\alpha=1$, $\beta=1$, $\lambda_1=(1-\sqrt{5})/2$,
$\lambda_2=(1+\sqrt{5})/2$, $f_n=0$, and
\begin{equation*}
A_n=\frac{\lambda_2^n-\lambda_1^n}{\lambda_2-\lambda_1}.
\end{equation*}
- The recurrence
\begin{equation*}
A_{n+1}=4A_n-4A_{n-1}+4^{n-1},
\end{equation*}
with $A_0=0$, $A_1=1$, so that $\alpha=4$, $\beta=-4$, $\lambda_1=\lambda_2=2$, $f_n=4^{n-1}$. From Eqn.~\eqref{11}, we get
\begin{equation*}
A_n=n2^{n-1}+2^{n-2}(2^n-n-1).
\end{equation*}
- The solution to your Q1 is given by Eqn.~\eqref{10} with $\lambda_2=3$ and $f_0=6$.
The above procedure can obviously be generalized to higher-order recurrences, by considering the eigenvalues of $T$ to be distinct, and then
deriving various subcases for repeated eigenvalues by taking appropriate limits as in the development above.