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

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

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

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

b = A("b")
f = B("f")
l = C("l")
d = D("d")

b.y = f
b.q = f
b.o = l
f.z = b
l.x = b
d.z = l
assert f.z.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.o: C = None
        self.q: B = None
        self.txt = txt

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

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

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

b = A("b")
f = B("f")
l = C("l")
d = D("d")

b.y = f
b.q = f
b.o = l
f.z = b
l.x = b
d.z = l
assert f.z.y.z.txt == "b"