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

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

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

f = A("f")
h = B("h")
d = C("d")
j = A("j")

f.p = j
f.v = j
f.q = h
h.v = f
h.s = d
d.t = j
d.s = h
j.p = f
j.v = f
j.q = h
assert h.v.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.v: A = None
        self.q: B = None
        self.txt = txt

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

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

f = A("f")
h = B("h")
d = C("d")
j = A("j")

f.p = j
f.v = j
f.q = h
h.v = f
h.s = d
d.t = j
d.s = h
j.p = f
j.v = f
j.q = h
assert h.v.q.s.txt == "d"