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: A = None
        self.s: B = None
        self.txt = txt

f = A("f")
a = B("a")
m = A("m")
g = B("g")
j = B("j")
k = A("k")
h = A("h")
i = B("i")

f.r = a
f.q = i
a.r = m
a.s = i
m.r = j
m.q = i
g.r = k
g.s = a
j.r = k
j.s = i
k.r = j
k.q = g
h.r = g
h.q = i
i.r = k
i.s = g
assert g.s.r.q.r.q.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: A = None
        self.s: B = None
        self.txt = txt

f = A("f")
a = B("a")
m = A("m")
g = B("g")
j = B("j")
k = A("k")
h = A("h")
i = B("i")

f.r = a
f.q = i
a.r = m
a.s = i
m.r = j
m.q = i
g.r = k
g.s = a
j.r = k
j.s = i
k.r = j
k.q = g
h.r = g
h.q = i
i.r = k
i.s = g
assert g.s.r.q.r.q.r.txt == "k"