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

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

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

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

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

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

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

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

d.o = f
d.w = f
e.y = l
e.u = g
e.x = a
g.u = a
f.o = l
f.w = d
a.y = d
a.u = g
a.x = e
l.o = d
l.w = f
assert a.x.x.x.y.o.txt == "d"