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

class B:
    def __init__(self, txt: str):
        self.r: B = 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.x: A = None
        self.q: D = None
        self.o: C = None
        self.txt = txt

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

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

class B:
    def __init__(self, txt: str):
        self.r: B = 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.x: A = None
        self.q: D = None
        self.o: C = None
        self.txt = txt

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

j.x = c
j.z = c
j.p = d
j.u = f
f.r = m
d.w = m
e.x = j
e.q = c
e.o = d
m.r = f
c.x = j
c.q = e
c.o = d
assert d.w.r.r.r.r.r.txt == "f"