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

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

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

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

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

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

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

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

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

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

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