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

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

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

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

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

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

h.t = a
b.s = h
f.t = a
k.t = b
a.s = h
assert a.s.t.s.txt == "h"