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

k = A("k")
a = B("a")
j = B("j")
f = A("f")
i = A("i")
d = B("d")
m = A("m")
c = A("c")

k.t = d
a.w = k
j.w = m
f.t = a
i.t = a
d.w = c
m.t = d
c.t = a
assert a.w.t.w.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

k = A("k")
a = B("a")
j = B("j")
f = A("f")
i = A("i")
d = B("d")
m = A("m")
c = A("c")

k.t = d
a.w = k
j.w = m
f.t = a
i.t = a
d.w = c
m.t = d
c.t = a
assert a.w.t.w.txt == "c"