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

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

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

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

a = A("a")
i = B("i")
f = C("f")
d = D("d")
l = A("l")
e = B("e")
j = B("j")

a.x = f
i.w = l
f.r = e
f.o = d
d.z = f
l.x = f
e.w = a
j.w = l
assert j.w.x.r.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

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

a = A("a")
i = B("i")
f = C("f")
d = D("d")
l = A("l")
e = B("e")
j = B("j")

a.x = f
i.w = l
f.r = e
f.o = d
d.z = f
l.x = f
e.w = a
j.w = l
assert j.w.x.r.w.x.txt == "f"