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

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

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

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

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

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

a.s = g
a.x = m
d.w = c
i.s = g
i.x = a
l.w = g
c.w = g
m.s = d
m.x = a
g.w = c
assert g.w.w.w.w.w.txt == "c"