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

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

d = A("d")
l = B("l")
k = A("k")
e = A("e")
h = B("h")
g = A("g")
i = B("i")
f = B("f")
j = A("j")

d.r = i
d.q = i
l.r = i
k.r = l
k.q = l
e.r = h
e.q = i
h.r = f
g.r = f
g.q = h
i.r = f
f.r = h
j.r = l
j.q = h
assert f.r.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.q: B = None
        self.txt = txt

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

d = A("d")
l = B("l")
k = A("k")
e = A("e")
h = B("h")
g = A("g")
i = B("i")
f = B("f")
j = A("j")

d.r = i
d.q = i
l.r = i
k.r = l
k.q = l
e.r = h
e.q = i
h.r = f
g.r = f
g.q = h
i.r = f
f.r = h
j.r = l
j.q = h
assert f.r.r.r.r.r.r.r.txt == "h"