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

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

a = A("a")
b = B("b")
k = B("k")
d = A("d")
n = B("n")
c = A("c")

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

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

a = A("a")
b = B("b")
k = B("k")
d = A("d")
n = B("n")
c = A("c")

a.t = b
b.w = c
k.w = d
d.t = b
n.w = a
c.t = b
assert c.t.w.t.w.t.txt == "b"