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

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

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

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

j.q = f
l.q = j
l.p = f
l.o = f
f.z = j
f.w = l
assert f.w.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

j.q = f
l.q = j
l.p = f
l.o = f
f.z = j
f.w = l
assert f.w.o.w.txt == "l"