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

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

class C:
    def __init__(self, txt: str):
        self.v: B = None
        self.q: B = None
        self.x: A = None
        self.txt = txt

n = A("n")
b = B("b")
h = C("h")
e = A("e")
g = B("g")

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

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

class C:
    def __init__(self, txt: str):
        self.v: B = None
        self.q: B = None
        self.x: A = None
        self.txt = txt

n = A("n")
b = B("b")
h = C("h")
e = A("e")
g = B("g")

n.z = b
b.u = h
b.t = h
b.p = n
h.v = g
h.q = g
h.x = e
e.z = g
g.u = h
g.t = h
g.p = e
assert h.x.z.p.z.txt == "g"