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

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

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

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

l = A("l")
n = B("n")
a = C("a")
d = D("d")
m = B("m")

l.y = n
n.x = m
n.r = m
n.z = d
a.o = m
d.o = m
d.w = n
d.z = n
m.x = n
m.r = n
m.z = d
assert d.w.r.r.z.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

l = A("l")
n = B("n")
a = C("a")
d = D("d")
m = B("m")

l.y = n
n.x = m
n.r = m
n.z = d
a.o = m
d.o = m
d.w = n
d.z = n
m.x = n
m.r = n
m.z = d
assert d.w.r.r.z.w.txt == "n"