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

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

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

a.s = l
g.w = f
g.r = f
d.w = a
d.r = a
f.s = g
l.w = a
l.r = a
assert d.w.s.r.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

a.s = l
g.w = f
g.r = f
d.w = a
d.r = a
f.s = g
l.w = a
l.r = a
assert d.w.s.r.s.r.txt == "a"