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

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

h = A("h")
b = B("b")
n = A("n")
l = A("l")
g = A("g")

h.t = n
h.z = b
b.p = h
n.t = l
n.z = b
l.t = g
l.z = b
g.t = l
g.z = b
assert h.z.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.z: B = None
        self.txt = txt

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

h = A("h")
b = B("b")
n = A("n")
l = A("l")
g = A("g")

h.t = n
h.z = b
b.p = h
n.t = l
n.z = b
l.t = g
l.z = b
g.t = l
g.z = b
assert h.z.p.t.txt == "n"