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

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

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

c = A("c")
f = B("f")
j = C("j")
n = A("n")
d = B("d")

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

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

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

c = A("c")
f = B("f")
j = C("j")
n = A("n")
d = B("d")

c.p = d
f.q = j
j.s = d
j.v = c
n.p = d
d.q = j
assert d.q.v.p.q.txt == "j"