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

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

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

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

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

d.r = l
m.p = l
m.y = d
m.r = d
m.x = b
i.y = a
i.t = l
i.s = l
i.x = d
a.w = d
e.p = i
e.y = d
e.r = d
e.x = b
l.y = b
l.t = i
l.s = i
l.x = d
f.y = a
f.t = i
f.s = i
f.x = d
b.w = d
assert e.r.r.y.w.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

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

d.r = l
m.p = l
m.y = d
m.r = d
m.x = b
i.y = a
i.t = l
i.s = l
i.x = d
a.w = d
e.p = i
e.y = d
e.r = d
e.x = b
l.y = b
l.t = i
l.s = i
l.x = d
f.y = a
f.t = i
f.s = i
f.x = d
b.w = d
assert e.r.r.y.w.r.t.txt == "i"