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

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

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

g.w = a
e.y = g
f.y = g
d.w = g
a.w = d
assert e.y.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

g.w = a
e.y = g
f.y = g
d.w = g
a.w = d
assert e.y.w.w.w.txt == "g"