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

class B:
    def __init__(self, txt: str):
        self.w: C = None
        self.y: A = None
        self.r: D = None
        self.x: D = None
        self.txt = txt

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

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

e = A("e")
j = B("j")
n = C("n")
d = D("d")
k = A("k")

e.x = d
j.w = n
j.y = e
j.r = d
j.x = d
n.w = j
d.o = j
k.x = d
assert n.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: C = None
        self.y: A = None
        self.r: D = None
        self.x: D = None
        self.txt = txt

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

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

e = A("e")
j = B("j")
n = C("n")
d = D("d")
k = A("k")

e.x = d
j.w = n
j.y = e
j.r = d
j.x = d
n.w = j
d.o = j
k.x = d
assert n.w.w.w.w.w.txt == "j"