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

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

b = A("b")
l = B("l")
n = B("n")
d = A("d")
k = B("k")
m = B("m")

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

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

b = A("b")
l = B("l")
n = B("n")
d = A("d")
k = B("k")
m = B("m")

b.q = d
b.s = n
l.p = d
l.t = b
n.p = d
n.t = b
d.q = b
d.s = n
k.p = b
k.t = b
m.p = b
m.t = b
assert n.t.q.s.txt == "n"