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

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

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

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

e = A("e")
j = B("j")
m = C("m")
i = D("i")

e.o = j
j.r = i
j.o = e
m.p = i
m.z = i
m.r = i
m.w = j
i.q = e
i.s = j
assert m.w.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

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

e = A("e")
j = B("j")
m = C("m")
i = D("i")

e.o = j
j.r = i
j.o = e
m.p = i
m.z = i
m.r = i
m.w = j
i.q = e
i.s = j
assert m.w.o.o.txt == "j"