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

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

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

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

g = A("g")
b = B("b")
e = C("e")
c = D("c")

g.r = c
b.p = c
b.r = g
e.y = c
c.r = g
c.s = g
c.z = e
c.t = e
assert c.t.y.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

g = A("g")
b = B("b")
e = C("e")
c = D("c")

g.r = c
b.p = c
b.r = g
e.y = c
c.r = g
c.s = g
c.z = e
c.t = e
assert c.t.y.r.r.txt == "c"