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

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

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

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

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

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

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

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

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

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

d.q = g
d.r = g
c.p = g
c.s = d
c.t = h
c.x = f
g.q = h
j.u = d
j.o = c
j.x = h
h.u = d
h.o = f
h.x = j
f.p = g
f.s = d
f.t = h
f.x = c
assert h.o.p.q.x.x.txt == "h"