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

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

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

h = A("h")
k = B("k")
c = C("c")
a = A("a")

h.p = a
h.r = c
h.y = k
k.p = a
k.v = c
c.q = h
a.p = h
a.r = c
a.y = k
assert h.p.p.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.r: C = None
        self.y: B = None
        self.txt = txt

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

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

h = A("h")
k = B("k")
c = C("c")
a = A("a")

h.p = a
h.r = c
h.y = k
k.p = a
k.v = c
c.q = h
a.p = h
a.r = c
a.y = k
assert h.p.p.y.p.txt == "a"