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

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

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

m.t = j
n.x = j
j.t = k
k.t = m
assert k.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

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

m.t = j
n.x = j
j.t = k
k.t = m
assert k.t.t.t.t.txt == "m"