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

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

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

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

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

b.z = d
f.x = c
d.t = j
j.r = a
j.o = f
c.z = a
a.t = j
assert j.r.t.o.x.z.t.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

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

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

b.z = d
f.x = c
d.t = j
j.r = a
j.o = f
c.z = a
a.t = j
assert j.r.t.o.x.z.t.txt == "j"