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

class B:
    def __init__(self, txt: str):
        self.z: C = None
        self.y: B = None
        self.q: C = None
        self.txt = txt

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

a = A("a")
f = B("f")
d = C("d")
b = A("b")
j = C("j")
c = B("c")

a.q = b
a.o = f
f.z = d
f.y = c
f.q = j
d.o = b
d.w = b
b.q = a
b.o = c
j.o = a
j.w = b
c.z = d
c.q = d
c.y = f
assert a.o.y.z.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.o: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.z: C = None
        self.y: B = None
        self.q: C = None
        self.txt = txt

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

a = A("a")
f = B("f")
d = C("d")
b = A("b")
j = C("j")
c = B("c")

a.q = b
a.o = f
f.z = d
f.y = c
f.q = j
d.o = b
d.w = b
b.q = a
b.o = c
j.o = a
j.w = b
c.z = d
c.q = d
c.y = f
assert a.o.y.z.o.q.txt == "a"