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

a = A("a")
j = B("j")
k = A("k")
m = A("m")

a.t = j
j.s = k
k.t = j
m.t = j
assert m.t.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

a = A("a")
j = B("j")
k = A("k")
m = A("m")

a.t = j
j.s = k
k.t = j
m.t = j
assert m.t.s.t.s.txt == "k"