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

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

m = A("m")
k = B("k")
a = B("a")
d = A("d")
n = A("n")

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

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

m = A("m")
k = B("k")
a = B("a")
d = A("d")
n = A("n")

m.w = d
k.x = n
k.t = n
a.x = n
a.t = m
d.w = m
n.w = m
assert k.t.w.w.w.w.txt == "d"