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

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

g = A("g")
h = B("h")
a = A("a")
c = B("c")

g.t = a
g.w = h
h.u = c
h.v = c
a.t = g
a.w = c
c.u = h
c.v = h
assert g.t.w.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.w: B = None
        self.txt = txt

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

g = A("g")
h = B("h")
a = A("a")
c = B("c")

g.t = a
g.w = h
h.u = c
h.v = c
a.t = g
a.w = c
c.u = h
c.v = h
assert g.t.w.u.u.txt == "c"