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

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

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

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

j.s = b
j.x = b
j.r = a
b.q = d
b.w = a
f.q = d
f.r = d
f.v = j
d.q = f
d.r = f
d.v = j
c.s = b
c.r = b
c.x = a
a.q = d
a.w = b
assert c.s.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.r: B = None
        self.x: B = None
        self.txt = txt

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

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

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

j.s = b
j.x = b
j.r = a
b.q = d
b.w = a
f.q = d
f.r = d
f.v = j
d.q = f
d.r = f
d.v = j
c.s = b
c.r = b
c.x = a
a.q = d
a.w = b
assert c.s.w.w.w.txt == "a"