Can you provide a proof or counterexample for the following claim?

>Let $P_m(x)=2^{-m}\cdot((x-\sqrt{x^2-4})^m+(x+\sqrt{x^2-4})^m)$ . 
Let $N= 4kp^{n}+1 $ where $k$ is a positive natural number , $ 4k<2^n$ , $p$ is a prime number and $n\ge3$ . Let $a$ be a natural number greater than two such that $\left(\frac{a-2}{N}\right)=-1$ and $\left(\frac{a+2}{N}\right)=-1$ where $\left(\frac{}{}\right)$ denotes Jacobi symbol. Let $S_i=P_p(S_{i-1})$ with $S_0$ equal to the modular $P_{kp^2}(a)\phantom{5} \text{mod} \phantom{5} N$. Then $N$ is prime if and only if $S_{n-2} \equiv 0 \pmod{N}$ .

You can run this test [here][1].

I have verified this claim for $k \in [1,500]$ with $p \leq 97$ and $n \in [3,50]$ .

**Further generalization of the claim**

**A**
>Let $P_m(x)=2^{-m}\cdot((x-\sqrt{x^2-4})^m+(x+\sqrt{x^2-4})^m)$ . 
Let $N= 2kp^{n} + 1 $ where $k$ is a positive natural number , $ 2k<2^n$ , $p$ is a prime number and $n\ge3$ . Let $a$ be a natural number greater than two such that $\left(\frac{a-2}{N}\right)=-1$ and $\left(\frac{a+2}{N}\right)=-1$ where $\left(\frac{}{}\right)$ denotes Jacobi symbol. Let $S_i=P_p(S_{i-1})$ with $S_0$ equal to the modular $P_{kp^2}(a)\phantom{5} \text{mod} \phantom{5} N$. Then $N$ is prime if and only if $S_{n-2} \equiv -2 \pmod{N}$ .

**B**
>Let $P_m(x)=2^{-m}\cdot((x-\sqrt{x^2-4})^m+(x+\sqrt{x^2-4})^m)$ . 
Let $N= 2kp^{n} - 1 $ where $k$ is a positive natural number , $ 2k<2^n$ , $p$ is a prime number and $n\ge3$ . Let $a$ be a natural number greater than two such that $\left(\frac{a-2}{N}\right)=1$ and $\left(\frac{a+2}{N}\right)=-1$ where $\left(\frac{}{}\right)$ denotes Jacobi symbol. Let $S_i=P_p(S_{i-1})$ with $S_0$ equal to the modular $P_{kp^2}(a)\phantom{5} \text{mod} \phantom{5} N$. Then $N$ is prime if and only if $S_{n-2} \equiv -2 \pmod{N}$ .


  [1]: https://sagecell.sagemath.org/?z=eJytU8FymzAQvfsrFA5BAiU1JL3EVqcznd7aXNxbEnsEXowGkDSSiO168u-VAddx6oMP1Um7j_f2sbsqjGqQ3TZ6i0SjlXEoGq30LbzyGgcOrMMV1VQStntk91EV6bmMkwlnd5N1KWrAV7gySkJegcH8JqWPhLGbBF1fo3f5-JAnlMcxmczYT7XEaaRVnZeQbW0Jr3ivndKE8k8p8Z9PcmdYMlTx9ymTXv4sU3vW7MiKWUImosAzxsbUgGuNxM60QA5BwWsLhLwFZLSEAn0rvc3hNx9GyB9RoGrKxn2wPwPxB3ew-b7RBgfPz_7qdhVqWutQBmhlwKMGuZJL9BuMuvL6pFOA2gvK6d0FevK8nlt_lPOz-MLSKJIXiN4fXdZgbS-ZziX6aFE5LKw2ogGsCblAWf8V7lhItk0G5r2shaOML-FXq2hl7oSSi5zXw44F9Klr_wu5tXwF2O_KfmBH5lkT1hns20Bi7yZfKhfE-4z28by_7uRbB3ZW4wQJ29s8-vvX43-rlCv_nKxwQ7WvQvpp8tx1K7fAFRNSt26RqQ3-TMMKPYR0LZauZOmYUH2K6lNUnqLyFOVdd5mFGnKnDH4KuwUPX2jWOqekZb98b2nNM6hZGB7m3NMQQ93T7yOCOsiWaj1khmdC_gBeNEzK&lang=sage&interacts=eJyLjgUAARUAuQ==