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

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

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

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

a = A("a")
i = B("i")
g = C("g")
d = D("d")
k = C("k")
m = A("m")
e = D("e")

a.r = d
a.u = m
i.w = e
i.t = e
i.x = a
g.o = e
g.w = m
g.q = m
d.w = i
d.r = e
k.o = e
k.w = a
k.q = m
m.r = e
m.u = a
e.w = i
e.r = d
assert e.r.w.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.u: A = None
        self.txt = txt

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

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

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

a = A("a")
i = B("i")
g = C("g")
d = D("d")
k = C("k")
m = A("m")
e = D("e")

a.r = d
a.u = m
i.w = e
i.t = e
i.x = a
g.o = e
g.w = m
g.q = m
d.w = i
d.r = e
k.o = e
k.w = a
k.q = m
m.r = e
m.u = a
e.w = i
e.r = d
assert e.r.w.x.r.txt == "d"