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

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

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

g = A("g")
b = B("b")
j = C("j")
h = C("h")
d = A("d")
a = C("a")
m = B("m")

g.y = d
g.r = j
b.o = h
b.y = m
j.u = h
j.x = b
h.u = j
h.x = b
d.y = g
d.r = h
a.u = h
a.x = b
m.o = h
m.y = b
assert h.u.u.x.y.y.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.r: C = None
        self.txt = txt

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

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

g = A("g")
b = B("b")
j = C("j")
h = C("h")
d = A("d")
a = C("a")
m = B("m")

g.y = d
g.r = j
b.o = h
b.y = m
j.u = h
j.x = b
h.u = j
h.x = b
d.y = g
d.r = h
a.u = h
a.x = b
m.o = h
m.y = b
assert h.u.u.x.y.y.o.x.txt == "b"