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

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

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

g = A("g")
m = B("m")
h = C("h")
c = B("c")
a = A("a")
j = C("j")

g.y = m
m.o = j
m.p = g
m.w = h
h.v = j
c.o = j
c.w = j
c.p = g
a.y = m
j.v = h
assert h.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
h = C("h")
c = B("c")
a = A("a")
j = C("j")

g.y = m
m.o = j
m.p = g
m.w = h
h.v = j
c.o = j
c.w = j
c.p = g
a.y = m
j.v = h
assert h.v.v.v.txt == "j"