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

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

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

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

f.z = d
b.q = f
b.o = f
b.v = k
k.s = f
d.q = f
d.o = f
d.v = k
assert d.v.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

f.z = d
b.q = f
b.o = f
b.v = k
k.s = f
d.q = f
d.o = f
d.v = k
assert d.v.s.z.txt == "d"