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

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

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

l = A("l")
f = B("f")
k = C("k")
d = C("d")

l.q = f
l.p = k
f.q = l
k.z = d
k.u = d
d.z = k
d.u = k
assert f.q.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: C = None
        self.txt = txt

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

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

l = A("l")
f = B("f")
k = C("k")
d = C("d")

l.q = f
l.p = k
f.q = l
k.z = d
k.u = d
d.z = k
d.u = k
assert f.q.p.z.txt == "d"