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

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

i = A("i")
l = B("l")
d = A("d")
c = B("c")
f = A("f")
a = B("a")
g = A("g")

i.y = f
i.s = f
l.x = c
l.s = i
d.y = g
d.s = i
c.x = a
c.s = f
f.y = d
f.s = g
a.x = c
a.s = f
g.y = i
g.s = i
assert i.s.s.s.s.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.s: A = None
        self.txt = txt

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

i = A("i")
l = B("l")
d = A("d")
c = B("c")
f = A("f")
a = B("a")
g = A("g")

i.y = f
i.s = f
l.x = c
l.s = i
d.y = g
d.s = i
c.x = a
c.s = f
f.y = d
f.s = g
a.x = c
a.s = f
g.y = i
g.s = i
assert i.s.s.s.s.y.txt == "d"