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

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

j = A("j")
a = B("a")
k = A("k")
h = B("h")
n = A("n")
c = B("c")
b = B("b")
f = B("f")
m = B("m")
g = B("g")

j.s = a
a.r = f
a.q = j
k.s = a
h.r = b
h.q = k
n.s = m
c.r = h
c.q = j
b.r = a
b.q = j
f.r = h
f.q = j
m.r = g
m.q = k
g.r = m
g.q = j
assert n.s.q.s.q.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

j = A("j")
a = B("a")
k = A("k")
h = B("h")
n = A("n")
c = B("c")
b = B("b")
f = B("f")
m = B("m")
g = B("g")

j.s = a
a.r = f
a.q = j
k.s = a
h.r = b
h.q = k
n.s = m
c.r = h
c.q = j
b.r = a
b.q = j
f.r = h
f.q = j
m.r = g
m.q = k
g.r = m
g.q = j
assert n.s.q.s.q.s.q.txt == "j"