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

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

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

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

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

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

i.w = k
a.p = h
a.t = i
l.w = a
h.p = a
h.t = i
k.p = h
k.t = i
assert k.p.t.w.txt == "k"