class A:
    def __init__(self, txt: str):
        self.y: D = 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.r: B = None
        self.v: A = None
        self.txt = txt

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

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

g.y = f
a.r = f
c.r = a
c.v = g
f.s = c
j.r = a
j.v = g
assert a.r.s.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = 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.r: B = None
        self.v: A = None
        self.txt = txt

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

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

g.y = f
a.r = f
c.r = a
c.v = g
f.s = c
j.r = a
j.v = g
assert a.r.s.r.r.txt == "f"