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

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

a = A("a")
l = B("l")
h = B("h")

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

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

a = A("a")
l = B("l")
h = B("h")

a.w = l
l.q = h
l.t = a
h.q = l
h.t = a
assert a.w.q.t.txt == "a"