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

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

class C:
    def __init__(self, txt: str):
        self.o: C = None
        self.w: C = None
        self.txt = txt

c = A("c")
e = B("e")
a = C("a")
m = B("m")
d = A("d")
g = C("g")

c.v = d
e.q = m
e.o = d
e.x = c
a.o = g
a.w = g
m.q = e
m.o = c
m.x = c
d.v = c
g.o = a
g.w = a
assert m.q.x.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.o: C = None
        self.w: C = None
        self.txt = txt

c = A("c")
e = B("e")
a = C("a")
m = B("m")
d = A("d")
g = C("g")

c.v = d
e.q = m
e.o = d
e.x = c
a.o = g
a.w = g
m.q = e
m.o = c
m.x = c
d.v = c
g.o = a
g.w = a
assert m.q.x.v.v.txt == "c"