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

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

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

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

d = A("d")
b = B("b")
m = C("m")
h = D("h")
f = A("f")
i = C("i")

d.y = i
d.o = m
d.q = m
b.o = m
b.x = i
m.s = h
m.u = f
h.o = b
h.s = f
f.y = m
f.q = m
f.o = i
i.s = h
i.u = d
assert i.s.s.o.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.o: C = None
        self.q: C = None
        self.txt = txt

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

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

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

d = A("d")
b = B("b")
m = C("m")
h = D("h")
f = A("f")
i = C("i")

d.y = i
d.o = m
d.q = m
b.o = m
b.x = i
m.s = h
m.u = f
h.o = b
h.s = f
f.y = m
f.q = m
f.o = i
i.s = h
i.u = d
assert i.s.s.o.u.txt == "d"