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

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

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

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

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

j.s = k
j.v = e
i.y = f
e.r = i
d.r = i
k.s = j
k.v = e
f.r = i
assert d.r.y.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.v: C = None
        self.txt = txt

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

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

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

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

j.s = k
j.v = e
i.y = f
e.r = i
d.r = i
k.s = j
k.v = e
f.r = i
assert d.r.y.r.y.txt == "f"