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

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

l = A("l")
c = B("c")
a = B("a")
g = A("g")
j = A("j")

l.r = c
c.o = a
c.p = g
a.o = c
a.p = g
g.r = c
j.r = c
assert g.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

l = A("l")
c = B("c")
a = B("a")
g = A("g")
j = A("j")

l.r = c
c.o = a
c.p = g
a.o = c
a.p = g
g.r = c
j.r = c
assert g.r.p.r.txt == "c"