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

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

a = A("a")
n = B("n")
e = A("e")
g = A("g")

a.s = g
a.r = e
n.w = a
e.s = g
e.r = g
g.s = e
g.r = e
assert e.s.r.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.r: A = None
        self.txt = txt

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

a = A("a")
n = B("n")
e = A("e")
g = A("g")

a.s = g
a.r = e
n.w = a
e.s = g
e.r = g
g.s = e
g.r = e
assert e.s.r.r.s.txt == "e"