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

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

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

a = A("a")
f = B("f")
g = C("g")
d = A("d")
h = C("h")
i = B("i")

a.v = h
a.r = i
a.p = i
f.q = h
f.v = a
g.y = a
g.s = h
d.v = g
d.r = f
d.p = f
h.y = a
h.s = g
i.q = h
i.v = a
assert f.q.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.r: B = None
        self.p: B = None
        self.txt = txt

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

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

a = A("a")
f = B("f")
g = C("g")
d = A("d")
h = C("h")
i = B("i")

a.v = h
a.r = i
a.p = i
f.q = h
f.v = a
g.y = a
g.s = h
d.v = g
d.r = f
d.p = f
h.y = a
h.s = g
i.q = h
i.v = a
assert f.q.s.s.txt == "h"