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

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

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

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

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

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

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

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

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