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

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

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

m = A("m")
d = B("d")
i = C("i")
g = A("g")
c = B("c")

m.p = g
m.v = i
m.q = c
d.u = g
i.y = d
g.p = m
g.v = i
g.q = d
c.u = m
assert c.u.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.v: C = None
        self.q: B = None
        self.txt = txt

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

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

m = A("m")
d = B("d")
i = C("i")
g = A("g")
c = B("c")

m.p = g
m.v = i
m.q = c
d.u = g
i.y = d
g.p = m
g.v = i
g.q = d
c.u = m
assert c.u.q.u.txt == "m"