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

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

j = A("j")
l = B("l")
a = A("a")
h = B("h")
c = A("c")
m = A("m")
e = A("e")
n = B("n")
d = B("d")
b = A("b")

j.x = m
l.x = m
a.x = m
h.x = j
c.x = e
m.x = a
e.x = a
n.x = a
d.x = j
b.x = a
assert c.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

j = A("j")
l = B("l")
a = A("a")
h = B("h")
c = A("c")
m = A("m")
e = A("e")
n = B("n")
d = B("d")
b = A("b")

j.x = m
l.x = m
a.x = m
h.x = j
c.x = e
m.x = a
e.x = a
n.x = a
d.x = j
b.x = a
assert c.x.x.x.x.x.x.txt == "a"