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

class B:
    def __init__(self, txt: str):
        self.t: C = None
        self.p: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.y: B = None
        self.t: A = None
        self.txt = txt

b = A("b")
c = B("c")
g = C("g")
l = B("l")
d = A("d")
m = C("m")

b.y = m
b.r = d
c.t = g
c.p = m
g.y = c
g.t = d
l.t = g
l.p = m
d.y = g
d.r = b
m.y = c
m.t = d
assert l.t.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.r: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: C = None
        self.p: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.y: B = None
        self.t: A = None
        self.txt = txt

b = A("b")
c = B("c")
g = C("g")
l = B("l")
d = A("d")
m = C("m")

b.y = m
b.r = d
c.t = g
c.p = m
g.y = c
g.t = d
l.t = g
l.p = m
d.y = g
d.r = b
m.y = c
m.t = d
assert l.t.t.r.txt == "b"