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

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

c = A("c")
f = B("f")
m = C("m")
a = D("a")

c.r = a
c.q = f
f.r = c
m.r = f
a.w = m
a.t = m
assert a.t.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.q: B = 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.txt = txt

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

c = A("c")
f = B("f")
m = C("m")
a = D("a")

c.r = a
c.q = f
f.r = c
m.r = f
a.w = m
a.t = m
assert a.t.r.r.txt == "c"