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

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

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

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

d = A("d")
a = B("a")
b = C("b")
i = D("i")

d.y = a
a.w = d
a.p = b
a.q = b
b.p = a
b.y = a
b.z = a
b.o = d
i.z = d
i.v = d
assert d.y.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

d = A("d")
a = B("a")
b = C("b")
i = D("i")

d.y = a
a.w = d
a.p = b
a.q = b
b.p = a
b.y = a
b.z = a
b.o = d
i.z = d
i.v = d
assert d.y.w.y.txt == "a"