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

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

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

f = A("f")
e = B("e")
a = C("a")
k = C("k")
d = A("d")

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

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

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

f = A("f")
e = B("e")
a = C("a")
k = C("k")
d = A("d")

f.y = d
f.x = e
e.y = k
e.w = d
e.o = a
a.r = e
a.x = e
k.r = e
k.x = e
d.y = f
d.x = e
assert d.y.y.x.o.txt == "a"