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

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

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

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

h = A("h")
d = B("d")
k = C("k")
e = D("e")
i = A("i")
j = B("j")
f = A("f")

h.o = f
h.q = k
d.q = e
d.v = k
k.z = j
k.r = j
e.t = k
e.z = f
i.o = f
i.q = k
j.q = e
j.v = k
f.o = i
f.q = k
assert i.o.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.q: C = None
        self.txt = txt

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

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

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

h = A("h")
d = B("d")
k = C("k")
e = D("e")
i = A("i")
j = B("j")
f = A("f")

h.o = f
h.q = k
d.q = e
d.v = k
k.z = j
k.r = j
e.t = k
e.z = f
i.o = f
i.q = k
j.q = e
j.v = k
f.o = i
f.q = k
assert i.o.q.r.txt == "j"