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

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

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

a = A("a")
m = B("m")
i = C("i")
b = B("b")
c = C("c")
d = A("d")
n = A("n")
g = A("g")

a.y = d
a.u = c
m.v = d
i.x = d
b.v = g
c.x = a
d.y = g
d.u = c
n.y = d
n.u = i
g.y = n
g.u = i
assert a.u.x.u.x.y.y.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.u: C = None
        self.txt = txt

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

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

a = A("a")
m = B("m")
i = C("i")
b = B("b")
c = C("c")
d = A("d")
n = A("n")
g = A("g")

a.y = d
a.u = c
m.v = d
i.x = d
b.v = g
c.x = a
d.y = g
d.u = c
n.y = d
n.u = i
g.y = n
g.u = i
assert a.u.x.u.x.y.y.u.txt == "i"