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

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

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

g = A("g")
b = B("b")
d = C("d")
n = C("n")
f = A("f")

g.x = b
g.q = b
g.s = b
b.r = d
b.p = f
d.w = n
n.w = d
f.x = b
f.q = b
f.s = b
assert d.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.q: B = None
        self.s: B = None
        self.txt = txt

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

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

g = A("g")
b = B("b")
d = C("d")
n = C("n")
f = A("f")

g.x = b
g.q = b
g.s = b
b.r = d
b.p = f
d.w = n
n.w = d
f.x = b
f.q = b
f.s = b
assert d.w.w.w.txt == "n"