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

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

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

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

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

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

n.t = m
d.s = a
d.y = a
m.t = f
l.t = h
g.t = l
h.t = f
f.t = m
b.t = l
a.s = d
a.y = d
assert a.s.y.y.y.y.s.txt == "a"