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.t: B = None
        self.txt = txt

k = A("k")
f = B("f")
e = B("e")
h = A("h")

k.t = f
f.w = k
f.t = e
e.w = k
e.t = f
h.t = f
assert k.t.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.t: B = None
        self.txt = txt

k = A("k")
f = B("f")
e = B("e")
h = A("h")

k.t = f
f.w = k
f.t = e
e.w = k
e.t = f
h.t = f
assert k.t.t.w.txt == "k"