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

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

j = A("j")
i = B("i")
n = A("n")
h = A("h")
e = A("e")
m = A("m")
a = B("a")
g = B("g")

j.t = g
i.x = m
n.t = a
h.t = a
e.t = i
m.t = i
a.x = j
g.x = e
assert j.t.x.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

j = A("j")
i = B("i")
n = A("n")
h = A("h")
e = A("e")
m = A("m")
a = B("a")
g = B("g")

j.t = g
i.x = m
n.t = a
h.t = a
e.t = i
m.t = i
a.x = j
g.x = e
assert j.t.x.t.txt == "i"