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

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

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

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

j = A("j")
e = B("e")
i = C("i")
f = D("f")
c = D("c")

j.w = i
j.o = e
e.r = j
i.u = j
i.p = j
i.r = j
i.x = e
f.z = e
f.s = e
c.z = e
c.s = e
assert j.o.r.o.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.o: B = None
        self.txt = txt

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

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

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

j = A("j")
e = B("e")
i = C("i")
f = D("f")
c = D("c")

j.w = i
j.o = e
e.r = j
i.u = j
i.p = j
i.r = j
i.x = e
f.z = e
f.s = e
c.z = e
c.s = e
assert j.o.r.o.txt == "e"