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

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

f = A("f")
m = B("m")
d = A("d")
l = A("l")
g = A("g")
n = A("n")
a = B("a")

f.x = n
m.y = a
d.x = f
l.x = g
g.x = l
n.x = g
a.y = m
assert g.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.y: B = None
        self.txt = txt

f = A("f")
m = B("m")
d = A("d")
l = A("l")
g = A("g")
n = A("n")
a = B("a")

f.x = n
m.y = a
d.x = f
l.x = g
g.x = l
n.x = g
a.y = m
assert g.x.x.x.x.txt == "g"