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

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

l = A("l")
h = B("h")
b = B("b")
j = B("j")

l.q = j
l.p = h
h.w = l
b.w = l
j.w = l
assert b.w.q.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: B = None
        self.txt = txt

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

l = A("l")
h = B("h")
b = B("b")
j = B("j")

l.q = j
l.p = h
h.w = l
b.w = l
j.w = l
assert b.w.q.w.p.txt == "h"