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

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

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

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

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

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

d.y = b
a.s = d
b.s = d
g.s = c
f.y = b
m.s = c
e.s = h
h.y = m
l.y = e
c.y = g
assert e.s.y.s.y.s.y.s.txt == "c"