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

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

m = A("m")
i = B("i")
c = B("c")
h = B("h")
e = A("e")
f = A("f")
g = A("g")
b = A("b")

m.x = g
i.s = c
i.y = h
c.s = h
c.y = h
h.s = c
h.y = i
e.x = m
f.x = m
g.x = f
b.x = g
assert f.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.s: B = None
        self.y: B = None
        self.txt = txt

m = A("m")
i = B("i")
c = B("c")
h = B("h")
e = A("e")
f = A("f")
g = A("g")
b = A("b")

m.x = g
i.s = c
i.y = h
c.s = h
c.y = h
h.s = c
h.y = i
e.x = m
f.x = m
g.x = f
b.x = g
assert f.x.x.x.x.txt == "m"