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

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

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

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

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

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

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

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

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