class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

a = A("a")
e = B("e")
h = B("h")
j = A("j")
k = B("k")
d = B("d")
i = B("i")
n = B("n")

a.t = n
e.p = a
h.p = j
j.t = k
k.p = j
d.p = j
i.p = j
n.p = j
assert d.p.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

a = A("a")
e = B("e")
h = B("h")
j = A("j")
k = B("k")
d = B("d")
i = B("i")
n = B("n")

a.t = n
e.p = a
h.p = j
j.t = k
k.p = j
d.p = j
i.p = j
n.p = j
assert d.p.t.p.txt == "j"