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

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

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

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

class E:
    def __init__(self, txt: str):
        self.r: C = None
        self.s: B = None
        self.txt = txt

b = A("b")
e = B("e")
h = C("h")
i = D("i")
m = E("m")
g = B("g")
f = D("f")
n = A("n")
j = C("j")

b.r = g
e.q = n
e.x = f
h.x = g
i.t = f
i.p = n
m.r = j
m.s = e
g.q = b
g.x = f
f.t = i
f.p = n
n.r = g
j.x = g
assert h.x.q.r.x.p.r.q.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.r: C = None
        self.s: B = None
        self.txt = txt

b = A("b")
e = B("e")
h = C("h")
i = D("i")
m = E("m")
g = B("g")
f = D("f")
n = A("n")
j = C("j")

b.r = g
e.q = n
e.x = f
h.x = g
i.t = f
i.p = n
m.r = j
m.s = e
g.q = b
g.x = f
f.t = i
f.p = n
n.r = g
j.x = g
assert h.x.q.r.x.p.r.q.r.x.txt == "f"