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

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

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

h = A("h")
j = B("j")
k = C("k")
c = B("c")
b = C("b")
g = C("g")

h.p = g
h.x = k
j.q = h
k.y = c
k.v = h
c.q = h
b.y = j
b.v = h
g.y = c
g.v = h
assert g.v.p.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.x: C = None
        self.txt = txt

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

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

h = A("h")
j = B("j")
k = C("k")
c = B("c")
b = C("b")
g = C("g")

h.p = g
h.x = k
j.q = h
k.y = c
k.v = h
c.q = h
b.y = j
b.v = h
g.y = c
g.v = h
assert g.v.p.y.q.txt == "h"