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

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

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

n.y = f
m.p = g
l.y = g
d.p = f
g.y = f
a.y = f
f.y = a
assert n.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

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