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

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

b = A("b")
e = B("e")
c = B("c")
k = A("k")
n = B("n")
m = B("m")

b.q = e
b.s = k
e.y = b
e.p = b
c.y = k
c.p = k
k.q = c
k.s = b
n.y = k
n.p = b
m.y = b
m.p = b
assert m.y.q.y.q.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: A = None
        self.txt = txt

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

b = A("b")
e = B("e")
c = B("c")
k = A("k")
n = B("n")
m = B("m")

b.q = e
b.s = k
e.y = b
e.p = b
c.y = k
c.p = k
k.q = c
k.s = b
n.y = k
n.p = b
m.y = b
m.p = b
assert m.y.q.y.q.y.s.txt == "k"