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

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

f = A("f")
m = B("m")
h = A("h")
c = A("c")
j = A("j")
e = A("e")
l = A("l")
i = A("i")
g = B("g")

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

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

f = A("f")
m = B("m")
h = A("h")
c = A("c")
j = A("j")
e = A("e")
l = A("l")
i = A("i")
g = B("g")

f.q = i
f.r = h
m.x = g
h.q = f
h.r = i
c.q = l
c.r = e
j.q = e
j.r = l
e.q = h
e.r = j
l.q = f
l.r = h
i.q = f
i.r = j
g.x = m
assert e.r.q.r.q.r.txt == "j"