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

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

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

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

l = A("l")
b = B("b")
a = C("a")
m = D("m")
j = D("j")
h = C("h")
d = C("d")
g = A("g")
n = A("n")

l.r = g
b.u = g
a.q = j
a.p = l
m.w = a
m.p = j
j.w = a
j.p = m
h.q = j
h.p = l
d.q = j
d.p = l
g.r = n
n.r = l
assert b.u.r.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

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

l = A("l")
b = B("b")
a = C("a")
m = D("m")
j = D("j")
h = C("h")
d = C("d")
g = A("g")
n = A("n")

l.r = g
b.u = g
a.q = j
a.p = l
m.w = a
m.p = j
j.w = a
j.p = m
h.q = j
h.p = l
d.q = j
d.p = l
g.r = n
n.r = l
assert b.u.r.r.r.r.r.r.r.txt == "n"