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

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

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

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

f = A("f")
b = B("b")
j = C("j")
l = D("l")
a = B("a")
m = C("m")
d = A("d")

f.t = l
b.r = d
j.r = a
j.x = m
l.y = m
a.r = d
m.r = a
m.x = j
d.t = l
assert d.t.y.x.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

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

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

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

f = A("f")
b = B("b")
j = C("j")
l = D("l")
a = B("a")
m = C("m")
d = A("d")

f.t = l
b.r = d
j.r = a
j.x = m
l.y = m
a.r = d
m.r = a
m.x = j
d.t = l
assert d.t.y.x.r.r.txt == "d"