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

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

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

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

m = A("m")
a = B("a")
f = C("f")
e = D("e")
b = D("b")
d = A("d")
k = D("k")
j = D("j")
i = D("i")
n = C("n")

m.q = d
m.r = n
a.o = f
a.u = f
f.u = d
e.r = j
b.r = j
d.q = m
d.r = n
k.r = e
j.r = b
i.r = k
n.u = d
assert i.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.r: C = None
        self.txt = txt

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

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

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

m = A("m")
a = B("a")
f = C("f")
e = D("e")
b = D("b")
d = A("d")
k = D("k")
j = D("j")
i = D("i")
n = C("n")

m.q = d
m.r = n
a.o = f
a.u = f
f.u = d
e.r = j
b.r = j
d.q = m
d.r = n
k.r = e
j.r = b
i.r = k
n.u = d
assert i.r.r.r.r.txt == "b"