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

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

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

l = A("l")
d = B("d")
m = C("m")
c = A("c")
n = C("n")
g = B("g")

l.q = c
l.s = g
l.r = d
d.y = m
d.v = c
d.w = n
m.u = n
m.p = n
m.r = c
c.q = l
c.s = d
c.r = d
n.u = m
n.p = m
n.r = l
g.y = m
g.w = m
g.v = c
assert c.s.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.s: B = None
        self.r: B = None
        self.txt = txt

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

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

l = A("l")
d = B("d")
m = C("m")
c = A("c")
n = C("n")
g = B("g")

l.q = c
l.s = g
l.r = d
d.y = m
d.v = c
d.w = n
m.u = n
m.p = n
m.r = c
c.q = l
c.s = d
c.r = d
n.u = m
n.p = m
n.r = l
g.y = m
g.w = m
g.v = c
assert c.s.w.p.txt == "m"