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

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

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

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

i = A("i")
j = B("j")
k = C("k")
d = D("d")
l = C("l")
b = D("b")
h = C("h")
g = C("g")
m = D("m")

i.x = m
j.p = l
k.u = i
k.r = g
d.p = m
l.u = i
l.r = k
b.p = m
h.u = i
h.r = l
g.u = i
g.r = l
m.p = d
assert i.x.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

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

i = A("i")
j = B("j")
k = C("k")
d = D("d")
l = C("l")
b = D("b")
h = C("h")
g = C("g")
m = D("m")

i.x = m
j.p = l
k.u = i
k.r = g
d.p = m
l.u = i
l.r = k
b.p = m
h.u = i
h.r = l
g.u = i
g.r = l
m.p = d
assert i.x.p.p.p.p.p.p.txt == "m"