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

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

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

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

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

f.r = d
l.r = e
i.u = l
e.o = k
j.u = l
k.u = l
d.r = f
assert k.u.r.o.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

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

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

f.r = d
l.r = e
i.u = l
e.o = k
j.u = l
k.u = l
d.r = f
assert k.u.r.o.u.r.txt == "e"