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

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

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

n = A("n")
d = B("d")
e = C("e")
i = B("i")
g = C("g")

n.o = i
d.v = g
d.t = i
e.o = n
e.x = n
e.r = g
i.v = e
i.t = d
g.o = n
g.x = n
g.r = e
assert i.v.x.o.v.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

n = A("n")
d = B("d")
e = C("e")
i = B("i")
g = C("g")

n.o = i
d.v = g
d.t = i
e.o = n
e.x = n
e.r = g
i.v = e
i.t = d
g.o = n
g.x = n
g.r = e
assert i.v.x.o.v.txt == "e"