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

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

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

d = A("d")
f = B("f")
j = C("j")
l = C("l")
m = C("m")

d.y = f
f.w = j
j.q = l
j.o = f
j.p = d
l.q = j
l.o = f
l.p = d
m.q = j
m.o = f
m.p = d
assert f.w.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

d = A("d")
f = B("f")
j = C("j")
l = C("l")
m = C("m")

d.y = f
f.w = j
j.q = l
j.o = f
j.p = d
l.q = j
l.o = f
l.p = d
m.q = j
m.o = f
m.p = d
assert f.w.o.w.txt == "j"