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

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

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

d = A("d")
g = B("g")
l = C("l")
b = B("b")
c = C("c")
n = A("n")

d.w = b
d.o = c
g.y = n
g.x = b
l.o = g
l.r = c
b.y = d
b.x = g
c.o = g
c.r = l
n.w = g
n.o = c
assert b.y.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.o: C = None
        self.txt = txt

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

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

d = A("d")
g = B("g")
l = C("l")
b = B("b")
c = C("c")
n = A("n")

d.w = b
d.o = c
g.y = n
g.x = b
l.o = g
l.r = c
b.y = d
b.x = g
c.o = g
c.r = l
n.w = g
n.o = c
assert b.y.w.x.txt == "g"