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

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

n = A("n")
a = B("a")
j = B("j")
k = A("k")
b = B("b")

n.q = j
n.w = k
a.t = b
a.p = k
j.t = a
j.p = k
k.q = b
k.w = n
b.t = j
b.p = k
assert n.w.q.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.w: A = None
        self.txt = txt

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

n = A("n")
a = B("a")
j = B("j")
k = A("k")
b = B("b")

n.q = j
n.w = k
a.t = b
a.p = k
j.t = a
j.p = k
k.q = b
k.w = n
b.t = j
b.p = k
assert n.w.q.p.w.txt == "n"