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

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

class C:
    def __init__(self, txt: str):
        self.w: C = None
        self.s: C = None
        self.y: B = None
        self.txt = txt

k = A("k")
e = B("e")
b = C("b")
g = C("g")

k.p = b
k.u = e
e.z = k
e.q = k
e.y = k
b.w = g
b.s = g
b.y = e
g.w = b
g.s = b
g.y = e
assert e.y.u.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.u: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.w: C = None
        self.s: C = None
        self.y: B = None
        self.txt = txt

k = A("k")
e = B("e")
b = C("b")
g = C("g")

k.p = b
k.u = e
e.z = k
e.q = k
e.y = k
b.w = g
b.s = g
b.y = e
g.w = b
g.s = b
g.y = e
assert e.y.u.z.txt == "k"