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

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

m = A("m")
h = B("h")
d = A("d")
f = A("f")
a = B("a")
k = A("k")
n = A("n")
b = B("b")

m.x = k
h.x = b
d.x = f
f.x = d
a.x = h
k.x = f
n.x = k
b.x = h
assert f.x.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: B = None
        self.txt = txt

m = A("m")
h = B("h")
d = A("d")
f = A("f")
a = B("a")
k = A("k")
n = A("n")
b = B("b")

m.x = k
h.x = b
d.x = f
f.x = d
a.x = h
k.x = f
n.x = k
b.x = h
assert f.x.x.x.x.x.x.x.txt == "d"