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

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

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

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

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

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

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

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

g.v = i
g.q = c
g.w = m
i.y = c
i.u = c
i.s = g
c.y = g
c.o = i
c.p = i
m.v = i
m.q = c
m.w = g
assert m.w.w.w.txt == "g"