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

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

d = A("d")
m = B("m")
f = B("f")
g = A("g")
l = A("l")
j = B("j")
h = B("h")
i = B("i")
n = B("n")

d.r = g
m.q = d
f.q = l
g.r = l
l.r = d
j.q = d
h.q = l
i.q = g
n.q = g
assert l.r.r.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.q: A = None
        self.txt = txt

d = A("d")
m = B("m")
f = B("f")
g = A("g")
l = A("l")
j = B("j")
h = B("h")
i = B("i")
n = B("n")

d.r = g
m.q = d
f.q = l
g.r = l
l.r = d
j.q = d
h.q = l
i.q = g
n.q = g
assert l.r.r.r.r.r.r.r.r.r.txt == "l"