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

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

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

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

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

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

b.t = a
b.w = k
k.w = b
a.t = b
a.w = k
assert a.t.t.w.txt == "k"