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

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

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

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

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

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

k.x = h
k.t = b
e.y = b
m.x = e
m.t = b
b.x = e
b.t = k
h.y = b
assert e.y.t.t.txt == "b"