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

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

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

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

g = A("g")
b = B("b")
d = C("d")
f = D("f")
j = B("j")
e = A("e")

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

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

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

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

g = A("g")
b = B("b")
d = C("d")
f = D("f")
j = B("j")
e = A("e")

g.r = b
g.o = e
b.z = d
b.q = j
b.u = g
b.x = f
d.p = f
d.t = g
f.s = d
j.z = d
j.q = b
j.u = g
j.x = f
e.r = j
e.o = g
assert f.s.p.s.p.s.txt == "d"