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

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

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

m = A("m")
h = B("h")
e = C("e")
f = C("f")
n = B("n")
a = B("a")
d = A("d")
g = B("g")
c = B("c")
b = C("b")

m.r = n
h.x = g
h.o = e
h.y = c
e.y = b
e.r = h
f.y = b
f.r = n
n.x = h
n.o = e
n.y = g
a.x = c
a.o = f
a.y = g
d.r = a
g.x = h
g.o = b
g.y = n
c.x = n
c.o = f
c.y = a
b.y = f
b.r = c
assert a.y.o.y.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

m = A("m")
h = B("h")
e = C("e")
f = C("f")
n = B("n")
a = B("a")
d = A("d")
g = B("g")
c = B("c")
b = C("b")

m.r = n
h.x = g
h.o = e
h.y = c
e.y = b
e.r = h
f.y = b
f.r = n
n.x = h
n.o = e
n.y = g
a.x = c
a.o = f
a.y = g
d.r = a
g.x = h
g.o = b
g.y = n
c.x = n
c.o = f
c.y = a
b.y = f
b.r = c
assert a.y.o.y.txt == "f"