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

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

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

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

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

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

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

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

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

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

i.u = c
i.p = g
c.x = j
j.p = c
k.y = c
k.u = i
g.u = f
g.p = i
h.y = f
h.u = i
b.p = c
f.x = j
assert c.x.p.x.p.x.txt == "j"