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

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

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

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

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

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

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

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

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

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

a.o = g
a.p = g
a.z = b
f.x = d
f.q = a
d.r = f
d.u = k
j.u = d
k.u = d
b.x = g
b.q = a
g.r = f
g.u = j
assert f.x.u.u.r.txt == "f"