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

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

c = A("c")
f = B("f")
g = C("g")
k = D("k")
m = C("m")
h = B("h")

c.q = m
f.y = k
g.r = c
k.q = g
m.r = c
h.y = k
assert g.r.q.r.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: 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: A = None
        self.txt = txt

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

c = A("c")
f = B("f")
g = C("g")
k = D("k")
m = C("m")
h = B("h")

c.q = m
f.y = k
g.r = c
k.q = g
m.r = c
h.y = k
assert g.r.q.r.q.r.txt == "c"