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

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

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

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

m.x = l
m.r = l
d.q = n
d.y = m
g.v = l
g.t = n
l.x = m
l.r = m
n.q = f
n.y = l
f.q = d
f.y = m
assert d.q.q.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.r: A = None
        self.txt = txt

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

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

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

m.x = l
m.r = l
d.q = n
d.y = m
g.v = l
g.t = n
l.x = m
l.r = m
n.q = f
n.y = l
f.q = d
f.y = m
assert d.q.q.y.txt == "m"