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

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

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

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

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

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

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

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

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

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

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