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

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

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

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

j = A("j")
d = B("d")
m = C("m")
l = D("l")
n = B("n")
k = B("k")
b = A("b")

j.o = b
d.r = n
d.y = j
m.x = d
l.o = n
l.z = j
l.y = k
l.q = m
n.r = d
n.y = b
k.r = n
k.y = j
b.o = j
assert k.y.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

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

j = A("j")
d = B("d")
m = C("m")
l = D("l")
n = B("n")
k = B("k")
b = A("b")

j.o = b
d.r = n
d.y = j
m.x = d
l.o = n
l.z = j
l.y = k
l.q = m
n.r = d
n.y = b
k.r = n
k.y = j
b.o = j
assert k.y.o.o.o.o.o.txt == "b"