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

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

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

f = A("f")
d = B("d")
c = C("c")
g = B("g")
j = C("j")
h = C("h")
a = C("a")

f.z = j
f.r = a
d.p = g
c.x = g
c.u = f
c.r = d
g.p = d
j.x = g
j.u = f
j.r = d
h.x = d
h.r = d
h.u = f
a.x = d
a.r = d
a.u = f
assert h.u.r.u.r.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.r: C = None
        self.txt = txt

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

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

f = A("f")
d = B("d")
c = C("c")
g = B("g")
j = C("j")
h = C("h")
a = C("a")

f.z = j
f.r = a
d.p = g
c.x = g
c.u = f
c.r = d
g.p = d
j.x = g
j.u = f
j.r = d
h.x = d
h.r = d
h.u = f
a.x = d
a.r = d
a.u = f
assert h.u.r.u.r.r.p.txt == "g"