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

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

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

n = A("n")
f = B("f")
i = C("i")
a = A("a")
b = B("b")

n.v = i
n.u = i
n.s = a
f.q = i
f.s = b
f.p = b
i.s = b
a.v = i
a.u = i
a.s = n
b.q = i
b.s = f
b.p = f
assert a.u.s.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.u: C = None
        self.s: A = None
        self.txt = txt

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

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

n = A("n")
f = B("f")
i = C("i")
a = A("a")
b = B("b")

n.v = i
n.u = i
n.s = a
f.q = i
f.s = b
f.p = b
i.s = b
a.v = i
a.u = i
a.s = n
b.q = i
b.s = f
b.p = f
assert a.u.s.q.s.txt == "b"