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

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

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

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

h = A("h")
c = B("c")
f = C("f")
m = D("m")
l = D("l")
g = B("g")
j = A("j")
a = C("a")

h.o = l
c.o = a
f.o = a
f.r = a
f.x = c
m.u = a
m.x = j
m.r = j
m.y = j
l.u = a
l.x = h
l.r = j
l.y = j
g.o = a
j.o = l
a.o = f
a.r = f
a.x = c
assert f.r.r.x.o.o.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

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

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

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

h = A("h")
c = B("c")
f = C("f")
m = D("m")
l = D("l")
g = B("g")
j = A("j")
a = C("a")

h.o = l
c.o = a
f.o = a
f.r = a
f.x = c
m.u = a
m.x = j
m.r = j
m.y = j
l.u = a
l.x = h
l.r = j
l.y = j
g.o = a
j.o = l
a.o = f
a.r = f
a.x = c
assert f.r.r.x.o.o.r.r.txt == "f"