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

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

k = A("k")
h = B("h")
b = A("b")

k.t = h
h.u = k
b.t = h
assert k.t.u.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

k = A("k")
h = B("h")
b = A("b")

k.t = h
h.u = k
b.t = h
assert k.t.u.t.txt == "h"