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

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

j = A("j")
g = B("g")
n = A("n")
k = B("k")
h = B("h")
l = A("l")
c = A("c")
a = A("a")

j.p = h
g.z = a
n.p = k
k.z = c
h.z = j
l.p = h
c.p = g
a.p = k
assert h.z.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

j = A("j")
g = B("g")
n = A("n")
k = B("k")
h = B("h")
l = A("l")
c = A("c")
a = A("a")

j.p = h
g.z = a
n.p = k
k.z = c
h.z = j
l.p = h
c.p = g
a.p = k
assert h.z.p.z.txt == "j"