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

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

c = A("c")
k = B("k")
f = B("f")
j = A("j")
g = B("g")
n = A("n")

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

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

c = A("c")
k = B("k")
f = B("f")
j = A("j")
g = B("g")
n = A("n")

c.q = k
c.s = g
k.r = g
f.r = g
j.q = f
j.s = g
g.r = f
n.q = k
n.s = g
assert j.s.r.r.r.r.txt == "g"